ailia  1.6.0.0
Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
ailia.AiliaModel Class Reference
Inheritance diagram for ailia.AiliaModel:
Inheritance graph
[legend]
Collaboration diagram for ailia.AiliaModel:
Collaboration graph
[legend]

Public Member Functions

bool Environment (int type)
 Selects the specified type of calculation environment. More...
 
string EnvironmentName ()
 Displays the name of the selected environment. More...
 
int GetEnvironmentCount ()
 Get the number of available computing environments (CPU, GPU). More...
 
Ailia.AILIAEnvironment GetEnvironment (int idx)
 Obtains the computing environment for the specified index. More...
 
bool SelectEnvironment (int idx)
 Select the calculation environment. More...
 
Ailia.AILIAEnvironment GetSelectedEnvironment ()
 Retrieves the selected computing environment. More...
 
bool SetMemoryMode (uint set_memory_mode)
 Sets the memory mode. More...
 
bool DisableLayerFusion ()
 Disables speedup due to layer fusion. More...
 
virtual bool OpenFile (string prototxt_path, string model_path)
 Create a network object from a model file. More...
 
virtual bool OpenMem (byte[] prototxt_buf, byte[] model_buf)
 Creates network objects from memory. More...
 
virtual bool OpenEx (Ailia.ailiaFileCallback callback, IntPtr arg1, IntPtr arg2)
 Creates a network object from a file callback. More...
 
bool Predict (float[] output_data, float[] input_data)
 Perform inference and obtain inference results. More...
 
Ailia.AILIAShape GetInputShape ()
 
uint[] GetInputShapeND ()
 Obtains the shape of the input data at the time of inference. More...
 
bool SetInputShape (Ailia.AILIAShape shape)
 Sets the shape of the input data during inference. More...
 
bool SetInputShapeND (uint[] shape, int dim)
 Change the shape of the input data during inference. More...
 
Ailia.AILIAShape GetOutputShape ()
 Obtains the shape of the output data during inference. More...
 
uint[] GetOutputShapeND ()
 Obtains the shape of the output data during inference. More...
 
Ailia.AILIAShape GetBlobShape (string layer_name)
 Obtains the shape (layer format) of the internal data (Blob) at the time of inference. (Obsolete) More...
 
int FindBlobIndexByName (string name)
 Look up and retrieve the index of the internal data (Blob) at the time of inference by name. More...
 
Ailia.AILIAShape GetBlobShape (uint idx)
 Obtains the shape (layer format) of the internal data (Blob) at the time of inference. More...
 
Ailia.AILIAShape GetBlobShape (int idx)
 
bool GetBlobData (float[] output_data, uint idx)
 Obtains internal data (Blob) at the time of inference. More...
 
bool GetBlobData (float[] output_data, int idx)
 
bool SetInputBlobData (float[] input_data, uint idx)
 Set input data to the specified Blob. More...
 
bool SetInputBlobData (float[] input_data, int idx)
 
bool SetInputBlobShape (Ailia.AILIAShape shape, uint idx)
 Sets the format of the specified input data (Blob). (4 dimensions or less) More...
 
bool SetInputBlobShape (Ailia.AILIAShape shape, int idx)
 
bool SetInputBlobShapeND (uint[] shape, uint dim, uint idx)
 Sets the format of the input data (Blob). (5D or more) More...
 
bool SetInputBlobShapeND (uint[] shape, int dim, int idx)
 
uint[] GetInputBlobList ()
 Obtains a list of the indices of the input data (Blob). More...
 
uint[] GetOutputBlobList ()
 Obtains a list of indices of the output data (Blob). More...
 
bool CopyBlobData (uint dst_blob_idx, uint src_blob_idx, AiliaModel src_model=null)
 Perform copies between blobs that specified. More...
 
bool Update ()
 Inference is performed with pre-populated data. More...
 
virtual void Close ()
 Destroys network objects. More...
 
virtual void Dispose ()
 Release resources. More...
 
string GetStatusString (int status)
 Returns a string corresponding to the status code. More...
 
string GetErrorDetail ()
 Returns error details. More...
 
bool SetProfileMode (uint profile_mode)
 Enable profile mode. More...
 
string GetSummary ()
 Obtain network information and profile results. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 

Protected Attributes

IntPtr ailia = IntPtr.Zero
 
bool logging = true
 

Properties

int Status [get, protected set]
 Status code @detail Get the library status code. More...
 

Member Function Documentation

◆ Close()

virtual void ailia.AiliaModel.Close ( )
inlinevirtual

Destroys network objects.

Destroys and initializes the network object.

Reimplemented in ailia.AiliaPoseEstimatorModel, ailia.AiliaFeatureExtractorModel, ailia.AiliaDetectorModel, and ailia.AiliaClassifierModel.

1566  {
1567  if (ailia != IntPtr.Zero)
1568  {
1569  Ailia.ailiaDestroy(ailia);
1570  ailia = IntPtr.Zero;
1571  }
1572  }
Definition: AiliaClassifierModel.cs:22

◆ CopyBlobData()

bool ailia.AiliaModel.CopyBlobData ( uint  dst_blob_idx,
uint  src_blob_idx,
AiliaModel  src_model = null 
)
inline

Perform copies between blobs that specified.

Parameters
dst_blob_idxThe index of destination blob
src_blob_idxThe index of source blob
src_mdoelThe model object that contains source blob. If specify null, perform copy blob inner this model object.
Returns
Returns true on success, false on failure.
1496  {
1497  IntPtr src_ailia = ailia;
1498  if (src_model != null) src_ailia = src_model.ailia;
1499  if (ailia == IntPtr.Zero || src_ailia == IntPtr.Zero) return false;
1500 
1501  int status = Status = Ailia.ailiaCopyBlobData(ailia, dst_blob_idx, src_ailia, src_blob_idx);
1502  if (status != Ailia.AILIA_STATUS_SUCCESS)
1503  {
1504  if (logging)
1505  {
1506  Debug.Log("ailiaUpdate failed " + status + " (" + GetStatusString(status) + ")");
1507  }
1508  return false;
1509  }
1510  return true;
1511  }
IntPtr ailia
Definition: AiliaModel.cs:25
string GetStatusString(int status)
Returns a string corresponding to the status code.
Definition: AiliaModel.cs:1618
int Status
Status code @detail Get the library status code.
Definition: AiliaModel.cs:1656
bool logging
Definition: AiliaModel.cs:33

◆ DisableLayerFusion()

bool ailia.AiliaModel.DisableLayerFusion ( )
inline

Disables speedup due to layer fusion.

Returns
Returns true on success, false on failure.

Disables speedup due to layer fusion. Default is enabled.

Remarks
This method will no effect (always retun false) after call OpenXXX Method.
389  {
390  if (ailia != IntPtr.Zero)
391  {
392  Debug.Assert(false, "Ailia instance is already initialized.");
393  return false;
394  }
395  disalbe_layer_fusion = true;
396  return true;
397  }

◆ Dispose() [1/2]

virtual void ailia.AiliaModel.Dispose ( )
inlinevirtual

Release resources.

Reimplemented in ailia.AiliaPoseEstimatorModel, ailia.AiliaFeatureExtractorModel, ailia.AiliaDetectorModel, and ailia.AiliaClassifierModel.

1582  {
1583  Dispose(true);
1584  }
virtual void Dispose()
Release resources.
Definition: AiliaModel.cs:1581

◆ Dispose() [2/2]

virtual void ailia.AiliaModel.Dispose ( bool  disposing)
inlineprotectedvirtual

Reimplemented in ailia.AiliaPoseEstimatorModel, ailia.AiliaFeatureExtractorModel, ailia.AiliaDetectorModel, and ailia.AiliaClassifierModel.

1587  {
1588  if (disposing){
1589  // release managed resource
1590  }
1591  Close(); // release unmanaged resource
1592  }
virtual void Close()
Destroys network objects.
Definition: AiliaModel.cs:1565

◆ Environment()

bool ailia.AiliaModel.Environment ( int  type)
inline

Selects the specified type of calculation environment.

環境選択(簡易)

Parameters
typeType of environment ( AILIA_ENVIRONMENT_TYPE_CPU or BLAS or GPU)
Returns
Returns true on success, false on failure.

Simply select the calculation environment from the environment type. To explicitly specify the computing environment, use GetEnvironmentCount(), GetEnvironment(), and SelectEnvironment().

Remarks
This method will no effect (always retun false) after call OpenXXX Method.
61  {
62  int count = GetEnvironmentCount();
63  if (count == -1)
64  {
65  return false;
66  }
67 
68  for (int i = 0; i < count; i++)
69  {
70  Ailia.AILIAEnvironment env = GetEnvironment(i);
71  if (env == null)
72  {
73  return false;
74  }
75 
76  if (env.type == type)
77  {
78  if (!SelectEnvironment(i))
79  {
80  return false;
81  }
82  if (env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_CUDA || env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_VULKAN)
83  {
84  return true; //優先
85  }
86  }
87  }
88  return true;
89  }
Ailia.AILIAEnvironment GetEnvironment(int idx)
Obtains the computing environment for the specified index.
Definition: AiliaModel.cs:161
bool SelectEnvironment(int idx)
Select the calculation environment.
Definition: AiliaModel.cs:202
int GetEnvironmentCount()
Get the number of available computing environments (CPU, GPU).
Definition: AiliaModel.cs:128

◆ EnvironmentName()

string ailia.AiliaModel.EnvironmentName ( )
inline

Displays the name of the selected environment.

Returns
Selected Environment Name

Returns the name of the selected environment.

107  {
108  return env_name;
109  }

◆ FindBlobIndexByName()

int ailia.AiliaModel.FindBlobIndexByName ( string  name)
inline

Look up and retrieve the index of the internal data (Blob) at the time of inference by name.

Parameters
layer_nameBlob name to search
Returns
Returns the index of the Blob specified by name on success, -1 otherwise.

Ailia.ailiaFindBlobIndexByName() searches for and retrieves the index of the internal data (Blob) at the time of inference by name.

1077  {
1078  uint idx = 0;
1079  int status = Status = Ailia.ailiaFindBlobIndexByName(ailia, ref idx, name);
1080  if (status != Ailia.AILIA_STATUS_SUCCESS)
1081  {
1082  if (logging)
1083  {
1084  Debug.Log("FindBlobIndexByName failed " + status + " (" + GetStatusString(status) + ")");
1085  }
1086  return -1;
1087  }
1088  return (int)idx;
1089  }

◆ GetBlobData() [1/2]

public bool ailia.AiliaModel.GetBlobData ( float[]  output_data,
int  idx 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

1197  {
1198  if (idx < 0)
1199  {
1200  return false;
1201  }
1202  return GetBlobData(output_data, (uint)idx);
1203  }
bool GetBlobData(float[] output_data, uint idx)
Obtains internal data (Blob) at the time of inference.
Definition: AiliaModel.cs:1166

◆ GetBlobData() [2/2]

bool ailia.AiliaModel.GetBlobData ( float[]  output_data,
uint  idx 
)
inline

Obtains internal data (Blob) at the time of inference.

Parameters
output_dataWhere to export inference results
idxIndex of Blob (0 to ailiaGetBlobCount() -1)
Returns
Returns true on success, false on failure.

Ailia.ailiaGetBlobData() to get the internal data (Blob) at the time of inference. If the inference has never been performed, it fails.

1167  {
1168  if (ailia == IntPtr.Zero)
1169  {
1170  return false;
1171  }
1172 
1173  GCHandle output_buf_handle = GCHandle.Alloc(output_data, GCHandleType.Pinned);
1174  IntPtr output_buf_ptr = output_buf_handle.AddrOfPinnedObject();
1175  int status = Status = Ailia.ailiaGetBlobData(ailia, output_buf_ptr, (uint)(output_data.Length * 4), idx);
1176  output_buf_handle.Free();
1177 
1178  if (status != Ailia.AILIA_STATUS_SUCCESS)
1179  {
1180  if (logging)
1181  {
1182  Debug.Log("ailiaGetBlobData failed " + status + " (" + GetStatusString(status) + ")");
1183  }
1184  return false;
1185  }
1186  return true;
1187  }

◆ GetBlobShape() [1/3]

public Ailia AILIAShape ailia.AiliaModel.GetBlobShape ( int  idx)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

1137  {
1138  if (idx < 0)
1139  {
1140  return null;
1141  }
1142  return GetBlobShape((uint)idx);
1143  }
Ailia.AILIAShape GetBlobShape(string layer_name)
Obtains the shape (layer format) of the internal data (Blob) at the time of inference....
Definition: AiliaModel.cs:1030

◆ GetBlobShape() [2/3]

Ailia.AILIAShape ailia.AiliaModel.GetBlobShape ( string  layer_name)
inline

Obtains the shape (layer format) of the internal data (Blob) at the time of inference. (Obsolete)

Parameters
layer_nameBlob name to search
Returns
If successful, return the shape of the Blob specified by name, otherwise null.

Ailia.ailiaFindBlobIndexByName() to get the index of a Blob from the Blob name. Ailia.ailiaGetBlobShape() obtains the shape (layer format) of the internal data (Blob) at the time of inference and stores it in shape.

1031  {
1032  if (ailia == IntPtr.Zero)
1033  {
1034  return null;
1035  }
1036  Ailia.AILIAShape shape = new Ailia.AILIAShape();
1037  uint id = 0;
1038  int status = Status = Ailia.ailiaFindBlobIndexByName(ailia, ref id, layer_name);
1039  if (status != Ailia.AILIA_STATUS_SUCCESS)
1040  {
1041  if (logging)
1042  {
1043  Debug.Log("ailiaFindBlobIndexByName failed " + status + " (" + GetStatusString(status) + ")");
1044  }
1045  return null;
1046  }
1047  status = Status = Ailia.ailiaGetBlobShape(ailia, shape, id, Ailia.AILIA_SHAPE_VERSION);
1048  if (status != Ailia.AILIA_STATUS_SUCCESS)
1049  {
1050  if (logging)
1051  {
1052  Debug.Log("ailiaGetBlobShape failed " + status + " (" + GetStatusString(status) + ")");
1053  }
1054  return null;
1055  }
1056  return shape;
1057  }

◆ GetBlobShape() [3/3]

Ailia.AILIAShape ailia.AiliaModel.GetBlobShape ( uint  idx)
inline

Obtains the shape (layer format) of the internal data (Blob) at the time of inference.

Parameters
idxIndex of Blob
Returns
If successful, return the shape of the Blob specified by name, otherwise null.

Ailia.ailiaGetBlobShape() obtains the shape (layer format) of the internal data (Blob) at the time of inference and stores it in shape.

1110  {
1111  if (ailia == IntPtr.Zero)
1112  {
1113  return null;
1114  }
1115 
1116  Ailia.AILIAShape shape = new Ailia.AILIAShape();
1117  int status = Status = Ailia.ailiaGetBlobShape(ailia, shape, idx, Ailia.AILIA_SHAPE_VERSION);
1118  if (status != Ailia.AILIA_STATUS_SUCCESS)
1119  {
1120  if (logging)
1121  {
1122  Debug.Log("ailiaGetBlobShape failed " + status + " (" + GetStatusString(status) + ")");
1123  }
1124  return null;
1125  }
1126  return shape;
1127  }

◆ GetEnvironment()

Ailia.AILIAEnvironment ailia.AiliaModel.GetEnvironment ( int  idx)
inline

Obtains the computing environment for the specified index.

Parameters
idxIndex of Environmental Information (0~ ailiaGetEnvironmentCount() -1)
Returns
Returns the available environment on success or null on failure.

Obtains detailed information about the specified computing environment.

162  {
163  IntPtr env_ptr = IntPtr.Zero;
164  int status = Status = Ailia.ailiaGetEnvironment(ref env_ptr, (uint)idx, Ailia.AILIA_ENVIRONMENT_VERSION);
165  if (status != Ailia.AILIA_STATUS_SUCCESS)
166  {
167  if (logging)
168  {
169  Debug.Log("ailiaGetEnvironment failed " + status + " (" + GetStatusString(status) + ")");
170  }
171  return null;
172  }
173  Ailia.AILIAEnvironment env = (Ailia.AILIAEnvironment)Marshal.PtrToStructure(env_ptr, typeof(Ailia.AILIAEnvironment));
174  if (logging)
175  {
176  //Debug.Log("ENV id:"+env.id+", name:"+Marshal.PtrToStringAnsi(env.name)+", type:"+env.type);
177  }
178  return env;
179  }

◆ GetEnvironmentCount()

int ailia.AiliaModel.GetEnvironmentCount ( )
inline

Get the number of available computing environments (CPU, GPU).

環境選択(詳細)

Returns
Returns the number of available environments on success, -1 on failure. 

Get the number of available environments.

129  {
130  SetTemporaryCachePath();
131  int count = 0;
132  int status = Status = Ailia.ailiaGetEnvironmentCount(ref count);
133  if (status != Ailia.AILIA_STATUS_SUCCESS)
134  {
135  if (logging)
136  {
137  Debug.Log("ailiaGetEnvironmentCount failed " + status + " (" + GetStatusString(status) + ")");
138  }
139  return -1;
140  }
141  return count;
142  }

◆ GetErrorDetail()

string ailia.AiliaModel.GetErrorDetail ( )
inline

Returns error details.

Returns
Returns a string with error details on success. @detail Returns the error details as a string.
1640  {
1641  return Marshal.PtrToStringAnsi(Ailia.ailiaGetErrorDetail(ailia));
1642  }

◆ GetInputBlobList()

uint [] ailia.AiliaModel.GetInputBlobList ( )
inline

Obtains a list of the indices of the input data (Blob).

Returns
Returns a list of input data (Blob) on success or null on failure. @detail Ailia.ailiaGetInputBlobCount() to get the number of input data (Blob) as count Ailia.ailiaGetBlobIndexByInputIndex() to get the index of the Blob as idx and create a list.
1404  {
1405  if (ailia == IntPtr.Zero)
1406  {
1407  return null;
1408  }
1409 
1410  uint count = 0;
1411  int status = Status = Ailia.ailiaGetInputBlobCount(ailia, ref count);
1412  if (status != Ailia.AILIA_STATUS_SUCCESS || count == 0)
1413  {
1414  return null;
1415  }
1416 
1417  uint[] r = new uint[count];
1418  for (uint i = 0; i < count; i++)
1419  {
1420  uint idx = 0;
1421  status = Status = Ailia.ailiaGetBlobIndexByInputIndex(ailia, ref idx, i);
1422  if (status != Ailia.AILIA_STATUS_SUCCESS)
1423  {
1424  break;
1425  }
1426  r[i] = idx;
1427  }
1428 
1429  return r;
1430  }

◆ GetInputShape()

Ailia.AILIAShape ailia.AiliaModel.GetInputShape ( )
inline
777  {
778  Ailia.AILIAShape shape = new Ailia.AILIAShape();
779  int status = Status = Ailia.ailiaGetInputShape(ailia, shape, Ailia.AILIA_SHAPE_VERSION);
780  if (status != Ailia.AILIA_STATUS_SUCCESS)
781  {
782  if (logging)
783  {
784  Debug.Log("ailiaGetInputShape failed " + status + " (" + GetStatusString(status) + ")");
785  }
786  return null;
787  }
788  return shape;
789  }

◆ GetInputShapeND()

uint [] ailia.AiliaModel.GetInputShapeND ( )
inline

Obtains the shape of the input data at the time of inference.

Returns
If successful, an array containing the size of each dimension of the input data is returned. shape Otherwise, null is returned. @detail AILIA.ailiaGetInputDim() is used to obtain the dimension of the input data during inference. AILIA.ailiaGetInputShapeND() is used to obtain the shape of the input data at the time of inference. If the shape has more than 5 dimensions, use GetInputShapeND(). If a part of the shape is not yet determined, the value of the corresponding dimension is set to 0, and valid values for the other dimensions are stored in shape. In case of failure, a corresponding error message will be displayed.
816  {
817  uint dim = 0;
818  int status = Status = Ailia.ailiaGetInputDim(ailia, ref dim);
819  if (status != Ailia.AILIA_STATUS_SUCCESS)
820  {
821  if (logging)
822  {
823  Debug.Log("ailiaGetInputDim failed " + status + " (" + GetStatusString(status) + ")");
824  }
825  return null;
826  }
827  uint[] shape = new uint[dim];
828  status = Status = Ailia.ailiaGetInputShapeND(ailia, shape, dim);
829  if (status != Ailia.AILIA_STATUS_SUCCESS)
830  {
831  if (logging)
832  {
833  Debug.Log("ailiaGetInputShapeND failed " + status + " (" + GetStatusString(status) + ")");
834  }
835  return null;
836  }
837  return shape;
838  }

◆ GetOutputBlobList()

uint [] ailia.AiliaModel.GetOutputBlobList ( )
inline

Obtains a list of indices of the output data (Blob).

Returns
Returns a list of input data (Blob) on success or null on failure. @detail Ailia.ailiaGetInputBlobCount() to get the number of output data (Blob) as count. Ailia.ailiaGetBlobIndexByInputIndex() to get the index of the Blob as idx and create a list.
1450  {
1451  if (ailia == IntPtr.Zero)
1452  {
1453  return null;
1454  }
1455 
1456  uint count = 0;
1457  int status = Status = Ailia.ailiaGetOutputBlobCount(ailia, ref count);
1458  if (status != Ailia.AILIA_STATUS_SUCCESS || count == 0)
1459  {
1460  return null;
1461  }
1462 
1463  uint[] r = new uint[count];
1464  for (uint i = 0; i < count; i++)
1465  {
1466  uint idx = 0;
1467  status = Status = Ailia.ailiaGetBlobIndexByOutputIndex(ailia, ref idx, i);
1468  if (status != Ailia.AILIA_STATUS_SUCCESS)
1469  {
1470  break;
1471  }
1472  r[i] = idx;
1473  }
1474  return r;
1475  }

◆ GetOutputShape()

Ailia.AILIAShape ailia.AiliaModel.GetOutputShape ( )
inline

Obtains the shape of the output data during inference.

Returns
Return shape on success, null otherwise.

Ailia.ailiaGetOutputShape() to get the shape of the output data during inference. If the shape has more than 5 dimensions, use GetOutputShapeND().

949  {
950  if (ailia == IntPtr.Zero)
951  {
952  return null;
953  }
954  Ailia.AILIAShape shape = new Ailia.AILIAShape();
955  int status = Status = Ailia.ailiaGetOutputShape(ailia, shape, Ailia.AILIA_SHAPE_VERSION);
956  if (status != Ailia.AILIA_STATUS_SUCCESS)
957  {
958  if (logging)
959  {
960  Debug.Log("ailiaGetOutputShape failed " + status + " (" + GetStatusString(status) + ")");
961  }
962  return null;
963  }
964  return shape;
965  }

◆ GetOutputShapeND()

uint [] ailia.AiliaModel.GetOutputShapeND ( )
inline

Obtains the shape of the output data during inference.

Returns
Ifsccessful, return shape, otheerwise null.

Get the dimension of the output data during inference with ailiaGetOutputDim(). Ailia.ailiaGetOutputShapeND() to get the shape of the output data during inference.

985  {
986  uint dim = 0;
987  int status = Status = Ailia.ailiaGetOutputDim(ailia, ref dim);
988  if (status != Ailia.AILIA_STATUS_SUCCESS)
989  {
990  if (logging)
991  {
992  Debug.Log("ailiaGetOutputDim failed " + status + " (" + GetStatusString(status) + ")");
993  }
994  return null;
995  }
996  uint[] shape = new uint[dim];
997  status = Status = Ailia.ailiaGetOutputShapeND(ailia, shape, dim);
998  if (status != Ailia.AILIA_STATUS_SUCCESS)
999  {
1000  if (logging)
1001  {
1002  Debug.Log("ailiaGetOutputShapeND failed " + status + " (" + GetStatusString(status) + ")");
1003  }
1004  return null;
1005  }
1006  return shape;
1007  }

◆ GetSelectedEnvironment()

Ailia.AILIAEnvironment ailia.AiliaModel.GetSelectedEnvironment ( )
inline

Retrieves the selected computing environment.

Returns
Returns computed environment information on success or null on failure.

Retrieves detailed information about the selected calculation environment.

235  {
236  IntPtr env_ptr = IntPtr.Zero;
237  int status = Status = Ailia.ailiaGetSelectedEnvironment(ailia, ref env_ptr, Ailia.AILIA_ENVIRONMENT_VERSION);
238  if (status != Ailia.AILIA_STATUS_SUCCESS)
239  {
240  if (logging)
241  {
242  Debug.Log("ailiaGetSelectedEnvironment failed " + status + " (" + GetStatusString(status) + ")");
243  }
244  return null;
245  }
246  Ailia.AILIAEnvironment env = (Ailia.AILIAEnvironment)Marshal.PtrToStructure(env_ptr, typeof(Ailia.AILIAEnvironment));
247  return env;
248  }

◆ GetStatusString()

string ailia.AiliaModel.GetStatusString ( int  status)
inline

Returns a string corresponding to the status code.

  • Parameters
    statusStatus code
    Returns
    Returns a string with error details on success. @detail Returns the error details corresponding to the status code as a string.
1619  {
1620  return Marshal.PtrToStringAnsi(Ailia.ailiaGetStatusString(status));
1621  }

◆ GetSummary()

string ailia.AiliaModel.GetSummary ( )
inline

Obtain network information and profile results.

Returns
Returns an ASCII string displaying the network information and profile results on success, or null on failure. @detail Obtains a string containing network information and profile results.
1706  {
1707  uint buffer_size = 0;
1708  int status = Status = Ailia.ailiaGetSummaryLength(ailia, ref buffer_size);
1709  if (status != Ailia.AILIA_STATUS_SUCCESS)
1710  {
1711  if (logging)
1712  {
1713  Debug.Log("ailiaGetSummaryLength failed " + status + " (" + GetStatusString(status) + ")");
1714  }
1715  return null;
1716  }
1717  byte[] buffer = new byte[buffer_size];
1718  status = Status = Ailia.ailiaSummary(ailia, buffer, buffer_size);
1719  if (status != Ailia.AILIA_STATUS_SUCCESS)
1720  {
1721  if (logging)
1722  {
1723  Debug.Log("ailiaSummary failed " + status + " (" + GetStatusString(status) + ")");
1724  }
1725  return null;
1726  }
1727  return System.Text.Encoding.ASCII.GetString(buffer);
1728  }

◆ OpenEx()

virtual bool ailia.AiliaModel.OpenEx ( Ailia.ailiaFileCallback  callback,
IntPtr  arg1,
IntPtr  arg2 
)
inlinevirtual

Creates a network object from a file callback.

Parameters
callbackUser-defined file access callback function structure
arg1Argument pointer notified to AILIA_USER_API_FOPEN
arg2Argument pointer notified to AILIA_USER_API_FOPEN
Returns
If this function is successful, it returns true , or false otherwise. @detail  Creates a network object from a file callback.

Reimplemented in ailia.AiliaPoseEstimatorModel, ailia.AiliaFeatureExtractorModel, ailia.AiliaDetectorModel, and ailia.AiliaClassifierModel.

621  {
622  Close();
623 
624  int status = Status = Ailia.ailiaCreate(ref ailia, env_id, Ailia.AILIA_MULTITHREAD_AUTO);
625  if (status != Ailia.AILIA_STATUS_SUCCESS)
626  {
627  DisplayLicenseError(status);
628  if (logging)
629  {
630  Debug.Log("ailiaCreate failed " + status + " (" + GetStatusString(status) + ")");
631  }
632  return false;
633  }
634 
635  if (memory_mode != Ailia.AILIA_MEMORY_OPTIMAIZE_DEFAULT)
636  {
637  status = Status = Ailia.ailiaSetMemoryMode(ailia, memory_mode);
638  if (status != Ailia.AILIA_STATUS_SUCCESS)
639  {
640  if (logging)
641  {
642  Debug.Log("ailiaSetMemoryMode failed " + status + " (" + GetStatusString(status) + ")");
643  }
644  Close();
645  return false;
646  }
647  }
648  if (disalbe_layer_fusion)
649  {
650  status = Status = Ailia.ailiaDisableLayerFusion(ailia);
651  if (status != Ailia.AILIA_STATUS_SUCCESS)
652  {
653  if (logging)
654  {
655  Debug.Log("ailiaDisableLayerFusion failed " + status + " (" + GetStatusString(status) + ")");
656  }
657  Close();
658  return false;
659  }
660  }
661 
662  if (arg1 != null)
663  {
664  status = Status = Ailia.ailiaOpenStreamEx(ailia, arg1, callback, Ailia.AILIA_FILE_CALLBACK_VERSION);
665  if (status != Ailia.AILIA_STATUS_SUCCESS)
666  {
667  if (logging)
668  {
669  Debug.Log("ailiaOpenStreamFileEx failed " + status + " (" + GetStatusString(status) + ")");
670  }
671  Close();
672  return false;
673  }
674  }
675 
676  status = Status = Ailia.ailiaOpenWeightEx(ailia, arg2, callback, Ailia.AILIA_FILE_CALLBACK_VERSION);
677  if (status != Ailia.AILIA_STATUS_SUCCESS)
678  {
679  if (logging)
680  {
681  Debug.Log("ailiaOpenWeightFileEx failed " + status + " (" + GetStatusString(status) + ")");
682  }
683  Close();
684  return false;
685  }
686 
687  return true;
688  }

◆ OpenFile()

virtual bool ailia.AiliaModel.OpenFile ( string  prototxt_path,
string  model_path 
)
inlinevirtual

Create a network object from a model file.

Parameters
prototxt_path Pathname of the prototxt file(MBSC or UTF16)
model_pathPath name of protobuf/onnx file(MBSC or UTF16)
Returns
If this function is successful, it returns true , or false otherwise. @detail Create a network object from a model file.

Reimplemented in ailia.AiliaPoseEstimatorModel, ailia.AiliaFeatureExtractorModel, ailia.AiliaDetectorModel, and ailia.AiliaClassifierModel.

423  {
424  Close();
425 
426  int status = Status = Ailia.ailiaCreate(ref ailia, env_id, Ailia.AILIA_MULTITHREAD_AUTO);
427  if (status != Ailia.AILIA_STATUS_SUCCESS)
428  {
429  DisplayLicenseError(status);
430  if (logging)
431  {
432  Debug.Log("ailiaCreate failed " + status + " (" + GetStatusString(status) + ")");
433  }
434  return false;
435  }
436 
437  if (memory_mode != Ailia.AILIA_MEMORY_OPTIMAIZE_DEFAULT)
438  {
439  status = Status = Ailia.ailiaSetMemoryMode(ailia, memory_mode);
440  if (status != Ailia.AILIA_STATUS_SUCCESS)
441  {
442  if (logging)
443  {
444  Debug.Log("ailiaSetMemoryMode failed " + status + " (" + GetStatusString(status) + ")");
445  }
446  Close();
447  return false;
448  }
449  }
450  if (disalbe_layer_fusion)
451  {
452  status = Status = Ailia.ailiaDisableLayerFusion(ailia);
453  if (status != Ailia.AILIA_STATUS_SUCCESS)
454  {
455  if (logging)
456  {
457  Debug.Log("ailiaDisableLayerFusion failed " + status + " (" + GetStatusString(status) + ")");
458  }
459  Close();
460  return false;
461  }
462  }
463 
464  if (prototxt_path != null)
465  {
466  status = Status = Ailia.ailiaOpenStreamFile(ailia, prototxt_path);
467  if (status != Ailia.AILIA_STATUS_SUCCESS)
468  {
469  if (logging)
470  {
471  Debug.Log("ailiaOpenStreamFile failed " + status + " (" + GetStatusString(status) + ")");
472  }
473  Close();
474  return false;
475  }
476  }
477 
478  status = Status = Ailia.ailiaOpenWeightFile(ailia, model_path);
479  if (status != Ailia.AILIA_STATUS_SUCCESS)
480  {
481  if (logging)
482  {
483  Debug.Log("ailiaOpenWeightFile failed " + status + " (" + GetStatusString(status) + ")");
484  }
485  Close();
486  return false;
487  }
488 
489  return true;
490  }

◆ OpenMem()

virtual bool ailia.AiliaModel.OpenMem ( byte[]  prototxt_buf,
byte[]  model_buf 
)
inlinevirtual

Creates network objects from memory.

Parameters
prototxt_bufPointer to data in  prototxt  file
model_bufPointer to data in protobuf/onnx file
Returns
If this function is successful, it returns true , or false otherwise. @detail Creates network objects from memory.

Reimplemented in ailia.AiliaPoseEstimatorModel, ailia.AiliaFeatureExtractorModel, ailia.AiliaDetectorModel, and ailia.AiliaClassifierModel.

516  {
517  Close();
518 
519  if (model_buf == null || model_buf.Length == 0 || (prototxt_buf != null && prototxt_buf.Length == 0))
520  {
521  if (logging)
522  {
523  Debug.Log("input buffer is empty");
524  }
525  return false;
526  }
527 
528  int status = Status = Ailia.ailiaCreate(ref ailia, env_id, Ailia.AILIA_MULTITHREAD_AUTO);
529  if (status != Ailia.AILIA_STATUS_SUCCESS)
530  {
531  DisplayLicenseError(status);
532  if (logging)
533  {
534  Debug.Log("ailiaCreate failed " + status + " (" + GetStatusString(status) + ")");
535  }
536  return false;
537  }
538 
539  if (memory_mode != Ailia.AILIA_MEMORY_OPTIMAIZE_DEFAULT)
540  {
541  status = Status = Ailia.ailiaSetMemoryMode(ailia, memory_mode);
542  if (status != Ailia.AILIA_STATUS_SUCCESS)
543  {
544  if (logging)
545  {
546  Debug.Log("ailiaSetMemoryMode failed " + status + " (" + GetStatusString(status) + ")");
547  }
548  Close();
549  return false;
550  }
551  }
552  if (disalbe_layer_fusion)
553  {
554  status = Status = Ailia.ailiaDisableLayerFusion(ailia);
555  if (status != Ailia.AILIA_STATUS_SUCCESS)
556  {
557  if (logging)
558  {
559  Debug.Log("ailiaDisableLayerFusion failed " + status + " (" + GetStatusString(status) + ")");
560  }
561  Close();
562  return false;
563  }
564  }
565 
566  if (prototxt_buf != null)
567  {
568  status = Status = Ailia.ailiaOpenStreamMem(ailia, prototxt_buf, (uint)prototxt_buf.Length);
569  if (status != Ailia.AILIA_STATUS_SUCCESS)
570  {
571  if (logging)
572  {
573  Debug.Log("ailiaOpenStreamMem failed " + status + " (" + GetStatusString(status) + ")");
574  }
575  Close();
576  return false;
577  }
578  }
579 
580  status = Status = Ailia.ailiaOpenWeightMem(ailia, model_buf, (uint)model_buf.Length);
581  if (status != Ailia.AILIA_STATUS_SUCCESS)
582  {
583  if (logging)
584  {
585  Debug.Log("ailiaOpenWeightMem filed " + status + " (" + GetStatusString(status) + ")");
586  }
587  Close();
588  return false;
589  }
590 
591  return true;
592  }

◆ Predict()

bool ailia.AiliaModel.Predict ( float[]  output_data,
float[]  input_data 
)
inline

Perform inference and obtain inference results.

Parameters
output_dataOutput data export destination
input_dataInference data
Returns
If this function is successful, it returns true , or false otherwise. @detail Ailia.ailiaPredict() is used to infer with input_data as input and output to output_data. This API is available for 1-input, 1-output models. To infer a multi-input/output model, use the SetInputBlobData, Update, and GetBlobData APIs.
719  {
720  if (ailia == IntPtr.Zero)
721  {
722  return false;
723  }
724 
725  //バッファの固定
726  GCHandle input_buf_handle = GCHandle.Alloc(input_data, GCHandleType.Pinned);
727  IntPtr input_buf_ptr = input_buf_handle.AddrOfPinnedObject();
728 
729  GCHandle output_buf_handle = GCHandle.Alloc(output_data, GCHandleType.Pinned);
730  IntPtr output_buf_ptr = output_buf_handle.AddrOfPinnedObject();
731 
732  //推論
733  int status = Status = Ailia.ailiaPredict(ailia, output_buf_ptr, (uint)(output_data.Length * 4), input_buf_ptr, (uint)(input_data.Length * 4));
734 
735  //バッファの開放
736  input_buf_handle.Free();
737  output_buf_handle.Free();
738 
739  if (status != Ailia.AILIA_STATUS_SUCCESS)
740  {
741  if (logging)
742  {
743  Debug.Log("ailiaPredict failed " + status + " (" + GetStatusString(status) + ")");
744  }
745  return false;
746  }
747  return true;
748  }

◆ SelectEnvironment()

bool ailia.AiliaModel.SelectEnvironment ( int  idx)
inline

Select the calculation environment.

Parameters
idxIndex of Environmental Information (0~ ailiaGetEnvironmentCount() -1)
Returns
Returns true on success, false on failure.

Selects the computing environment for the specified index as the inference environment.

Remarks
This method will no effect (always retun false) after call OpenXXX Method.
203  {
204  Ailia.AILIAEnvironment env = GetEnvironment(idx);
205  if (env == null)
206  {
207  return false;
208  }
209  if (ailia != IntPtr.Zero)
210  {
211  Debug.Assert(false, "Ailia instance is already initialized.");
212  return false;
213  }
214  env_id = env.id;
215  env_name = Marshal.PtrToStringAnsi(env.name);
216  return true;
217  }

◆ SetInputBlobData() [1/2]

public bool ailia.AiliaModel.SetInputBlobData ( float[]  input_data,
int  idx 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

1255  {
1256  if (ailia == IntPtr.Zero || idx < 0)
1257  {
1258  return false;
1259  }
1260  return SetInputBlobData(input_data, (uint)idx);
1261  }
bool SetInputBlobData(float[] input_data, uint idx)
Set input data to the specified Blob.
Definition: AiliaModel.cs:1224

◆ SetInputBlobData() [2/2]

bool ailia.AiliaModel.SetInputBlobData ( float[]  input_data,
uint  idx 
)
inline

Set input data to the specified Blob.

Parameters
input_dataInference data X,Y,Z,W, in that order, stored as numeric type Size is inputSize of net file (I'm not sure if this is strictly the same as ailia.cs description, since buffer is allocated)
idxIndex of Blob to change settings
Returns
Returns true on success, false on failure.

Ailia.ailiaSetInPutBlobData() gives the input data to the specified Blob.

1225  {
1226  if (ailia == IntPtr.Zero)
1227  {
1228  return false;
1229  }
1230 
1231  GCHandle input_buf_handle = GCHandle.Alloc(input_data, GCHandleType.Pinned);
1232  IntPtr input_buf_ptr = input_buf_handle.AddrOfPinnedObject();
1233  int status = Status = Ailia.ailiaSetInputBlobData(ailia, input_buf_ptr, (uint)(input_data.Length * 4), idx);
1234  input_buf_handle.Free();
1235 
1236  if (status != Ailia.AILIA_STATUS_SUCCESS)
1237  {
1238  if (logging)
1239  {
1240  Debug.Log("ailiaSetInputBlobData failed " + status + " (" + GetStatusString(status) + ")");
1241  }
1242  return false;
1243  }
1244  return true;
1245  }

◆ SetInputBlobShape() [1/2]

public bool ailia.AiliaModel.SetInputBlobShape ( Ailia.AILIAShape  shape,
int  idx 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

1317  {
1318  if (idx < 0)
1319  {
1320  return false;
1321  }
1322  return SetInputBlobShape(shape, (uint)idx);
1323  }
bool SetInputBlobShape(Ailia.AILIAShape shape, uint idx)
Sets the format of the specified input data (Blob). (4 dimensions or less)
Definition: AiliaModel.cs:1290

◆ SetInputBlobShape() [2/2]

bool ailia.AiliaModel.SetInputBlobShape ( Ailia.AILIAShape  shape,
uint  idx 
)
inline

Sets the format of the specified input data (Blob). (4 dimensions or less)

Parameters
shapeShape information of input data
idxIndex of Blob to be changed
Returns
Returns true on success, false on failure. @detail Used to change the input shape of a network with multiple inputs, for example. Changes the format of the input data (Blob) specified in Ailia.ailiaSetInputBlobShape(). If the input shape has a rank of 5 or more dimensions, use SetInputShapeND().
1291  {
1292  if (ailia == IntPtr.Zero)
1293  {
1294  return false;
1295  }
1296 
1297  int status = Status = Ailia.ailiaSetInputBlobShape(ailia, shape, idx, Ailia.AILIA_SHAPE_VERSION);
1298  if (status != Ailia.AILIA_STATUS_SUCCESS)
1299  {
1300  if (logging)
1301  {
1302  Debug.Log("ailiaSetInputBlobShape failed " + status + " (" + GetStatusString(status) + ")");
1303  }
1304  return false;
1305  }
1306  return true;
1307  }

◆ SetInputBlobShapeND() [1/2]

public bool ailia.AiliaModel.SetInputBlobShapeND ( uint[]  shape,
int  dim,
int  idx 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

1375  {
1376  if (idx < 0 || dim < 0)
1377  {
1378  return false;
1379  }
1380  return SetInputBlobShapeND(shape, (uint)dim, (uint)idx);
1381  }
bool SetInputBlobShapeND(uint[] shape, uint dim, uint idx)
Sets the format of the input data (Blob). (5D or more)
Definition: AiliaModel.cs:1348

◆ SetInputBlobShapeND() [2/2]

bool ailia.AiliaModel.SetInputBlobShapeND ( uint[]  shape,
uint  dim,
uint  idx 
)
inline

Sets the format of the input data (Blob). (5D or more)

Parameters
shapeShape information of input data
dimDimensions of shape
idxIndex of Blob to be changed
Returns
Returns true on success, false on failure. @detail Used to change the input shape of a network with multiple inputs, for example. Changes the format of the input data (Blob) specified in Ailia.ailiaSetInputBlobShapeND().
1349  {
1350  if (ailia == IntPtr.Zero)
1351  {
1352  return false;
1353  }
1354 
1355  int status = Status = Ailia.ailiaSetInputBlobShapeND(ailia, shape, dim, idx);
1356  if (status != Ailia.AILIA_STATUS_SUCCESS)
1357  {
1358  if (logging)
1359  {
1360  Debug.Log("ailiaSetInputBlobShapeND failed " + status + " (" + GetStatusString(status) + ")");
1361  }
1362  return false;
1363  }
1364  return true;
1365  }

◆ SetInputShape()

bool ailia.AiliaModel.SetInputShape ( Ailia.AILIAShape  shape)
inline

Sets the shape of the input data during inference.

Parameters
shapeShape information of input data
Returns
If this function is successful, it returns true , or false otherwise. @detail Changes the input geometry defined in prototxt. It should be the same as the rank described in prototxt. Note that an error may be returned if the shape of the weight coefficients depends on the input geometry, for example. If the rank defined in prototxt is 5 or more dimensions, use SetInputShapeND().
868  {
869  if (ailia == IntPtr.Zero)
870  {
871  return false;
872  }
873 
874  int status = Status = Ailia.ailiaSetInputShape(ailia, shape, Ailia.AILIA_SHAPE_VERSION);
875  if (status != Ailia.AILIA_STATUS_SUCCESS)
876  {
877  if (logging)
878  {
879  Debug.Log("ailiaSetInputShape failed " + status + " (" + GetStatusString(status) + ")");
880  }
881  return false;
882  }
883  return true;
884  }

◆ SetInputShapeND()

bool ailia.AiliaModel.SetInputShapeND ( uint[]  shape,
int  dim 
)
inline

Change the shape of the input data during inference.

Parameters
netNetwork object pointer
shapeArray of sizes of each dimension of input data (dim-1, dim-2, ... ,1, 0)
dimDimensions of shape
Returns
If this function is successful, it returns true , or false otherwise.

Changes the input geometry defined in prototxt. It should be the same as the rank described in prototxt. Note that an error may be returned if the shape of the weight coefficients depends on the input geometry, for example.

912  {
913  if (ailia == IntPtr.Zero || dim < 0)
914  {
915  return false;
916  }
917 
918  int status = Status = Ailia.ailiaSetInputShapeND(ailia, shape, (uint)dim);
919  if (status != Ailia.AILIA_STATUS_SUCCESS)
920  {
921  if (logging)
922  {
923  Debug.Log("ailiaSetInputShapeND failed " + status + " (" + GetStatusString(status) + ")");
924  }
925  return false;
926  }
927  return true;
928  }

◆ SetMemoryMode()

bool ailia.AiliaModel.SetMemoryMode ( uint  set_memory_mode)
inline

Sets the memory mode.

Parameters
set_memory_modeMemory mode (multiple specifiable by logical. AILIA_MEMORY_XXX (default: AILIA_MEMORY_REDUCE_CONSTANT )
Returns
Returns true on success, false on failure.

Changes the memory usage policy setting; if anything other than AILIA_MEMORY_NO_OPTIMIZATION is specified, the intermediate buffer allocated during inference is released, thus reducing the amount of memory used during inference.

Remarks
This method will no effect (always retun false) after call OpenXXX Method.
359  {
360  if (ailia != IntPtr.Zero)
361  {
362  Debug.Assert(false, "Ailia instance is already initialized.");
363  return false;
364  }
365  memory_mode = set_memory_mode;
366  return true;
367  }

◆ SetProfileMode()

bool ailia.AiliaModel.SetProfileMode ( uint  profile_mode)
inline

Enable profile mode.

Returns
Returns true on success, false on failure. @detail Enable profile mode. After enabling profile mode and inference, get profile results in Summary API.
1675  {
1676  int status = Status = Ailia.ailiaSetProfileMode(ailia, profile_mode);
1677  if (status != Ailia.AILIA_STATUS_SUCCESS)
1678  {
1679  if (logging)
1680  {
1681  Debug.Log("ailiaSetProfileMode failed " + status + " (" + GetStatusString(status) + ")");
1682  }
1683  return false;
1684  }
1685  return true;
1686  }

◆ Update()

bool ailia.AiliaModel.Update ( )
inline

Inference is performed with pre-populated data.

Returns
Returns true on success, false on failure. @detail This is used, for example, when SetInputBlobData() is used to provide input. Inference results should be obtained with GetBlobData().
1534  {
1535  if (ailia == IntPtr.Zero)
1536  {
1537  return false;
1538  }
1539  int status = Status = Ailia.ailiaUpdate(ailia);
1540  if (status != Ailia.AILIA_STATUS_SUCCESS)
1541  {
1542  if (logging)
1543  {
1544  Debug.Log("ailiaUpdate failed " + status + " (" + GetStatusString(status) + ")");
1545  }
1546  return false;
1547  }
1548  return true;
1549  }

Member Data Documentation

◆ ailia

IntPtr ailia.AiliaModel.ailia = IntPtr.Zero
protected

◆ logging

bool ailia.AiliaModel.logging = true
protected

Property Documentation

◆ Status

int ailia.AiliaModel.Status
getprotected set

Status code @detail Get the library status code.

1656 { get; protected set; }

The documentation for this class was generated from the following file: