ailia  1.5.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...
 
void SetMemoryMode (uint set_memory_mode)
 Sets the memory mode. More...
 
void 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.

1529  {
1530  if (ailia != IntPtr.Zero)
1531  {
1532  Ailia.ailiaDestroy(ailia);
1533  ailia = IntPtr.Zero;
1534  }
1535  }
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.
1459  {
1460  IntPtr src_ailia = ailia;
1461  if (src_model != null) src_ailia = src_model.ailia;
1462  if (ailia == IntPtr.Zero || src_ailia == IntPtr.Zero) return false;
1463 
1464  int status = Status = Ailia.ailiaCopyBlobData(ailia, dst_blob_idx, src_ailia, src_blob_idx);
1465  if (status != Ailia.AILIA_STATUS_SUCCESS)
1466  {
1467  if (logging)
1468  {
1469  Debug.Log("ailiaUpdate failed " + status + " (" + GetStatusString(status) + ")");
1470  }
1471  return false;
1472  }
1473  return true;
1474  }
IntPtr ailia
Definition: AiliaModel.cs:25
string GetStatusString(int status)
Returns a string corresponding to the status code.
Definition: AiliaModel.cs:1581
int Status
Status code @detail Get the library status code.
Definition: AiliaModel.cs:1619
bool logging
Definition: AiliaModel.cs:33

◆ DisableLayerFusion()

void ailia.AiliaModel.DisableLayerFusion ( )
inline

Disables speedup due to layer fusion.

Disables speedup due to layer fusion. Default is enabled.

358  {
359  disalbe_layer_fusion = true;
360  }

◆ Dispose() [1/2]

virtual void ailia.AiliaModel.Dispose ( )
inlinevirtual

Release resources.

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

1545  {
1546  Dispose(true);
1547  }
virtual void Dispose()
Release resources.
Definition: AiliaModel.cs:1544

◆ Dispose() [2/2]

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

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

1550  {
1551  if (disposing){
1552  // release managed resource
1553  }
1554  Close(); // release unmanaged resource
1555  }
virtual void Close()
Destroys network objects.
Definition: AiliaModel.cs:1528

◆ 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().

57  {
58  int count = GetEnvironmentCount();
59  if (count == -1)
60  {
61  return false;
62  }
63 
64  for (int i = 0; i < count; i++)
65  {
66  Ailia.AILIAEnvironment env = GetEnvironment(i);
67  if (env == null)
68  {
69  return false;
70  }
71 
72  if (env.type == type)
73  {
74  if (!SelectEnvironment(i))
75  {
76  return false;
77  }
78  if (env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_CUDA || env.backend == Ailia.AILIA_ENVIRONMENT_BACKEND_VULKAN)
79  {
80  return true; //優先
81  }
82  }
83  }
84  return true;
85  }
Ailia.AILIAEnvironment GetEnvironment(int idx)
Obtains the computing environment for the specified index.
Definition: AiliaModel.cs:157
bool SelectEnvironment(int idx)
Select the calculation environment.
Definition: AiliaModel.cs:194
int GetEnvironmentCount()
Get the number of available computing environments (CPU, GPU).
Definition: AiliaModel.cs:124

◆ EnvironmentName()

string ailia.AiliaModel.EnvironmentName ( )
inline

Displays the name of the selected environment.

Returns
Selected Environment Name

Returns the name of the selected environment.

103  {
104  return env_name;
105  }

◆ 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.

1040  {
1041  uint idx = 0;
1042  int status = Status = Ailia.ailiaFindBlobIndexByName(ailia, ref idx, name);
1043  if (status != Ailia.AILIA_STATUS_SUCCESS)
1044  {
1045  if (logging)
1046  {
1047  Debug.Log("FindBlobIndexByName failed " + status + " (" + GetStatusString(status) + ")");
1048  }
1049  return -1;
1050  }
1051  return (int)idx;
1052  }

◆ 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.

1160  {
1161  if (idx < 0)
1162  {
1163  return false;
1164  }
1165  return GetBlobData(output_data, (uint)idx);
1166  }
bool GetBlobData(float[] output_data, uint idx)
Obtains internal data (Blob) at the time of inference.
Definition: AiliaModel.cs:1129

◆ 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.

1130  {
1131  if (ailia == IntPtr.Zero)
1132  {
1133  return false;
1134  }
1135 
1136  GCHandle output_buf_handle = GCHandle.Alloc(output_data, GCHandleType.Pinned);
1137  IntPtr output_buf_ptr = output_buf_handle.AddrOfPinnedObject();
1138  int status = Status = Ailia.ailiaGetBlobData(ailia, output_buf_ptr, (uint)(output_data.Length * 4), idx);
1139  output_buf_handle.Free();
1140 
1141  if (status != Ailia.AILIA_STATUS_SUCCESS)
1142  {
1143  if (logging)
1144  {
1145  Debug.Log("ailiaGetBlobData failed " + status + " (" + GetStatusString(status) + ")");
1146  }
1147  return false;
1148  }
1149  return true;
1150  }

◆ 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.

1100  {
1101  if (idx < 0)
1102  {
1103  return null;
1104  }
1105  return GetBlobShape((uint)idx);
1106  }
Ailia.AILIAShape GetBlobShape(string layer_name)
Obtains the shape (layer format) of the internal data (Blob) at the time of inference....
Definition: AiliaModel.cs:993

◆ 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.

994  {
995  if (ailia == IntPtr.Zero)
996  {
997  return null;
998  }
999  Ailia.AILIAShape shape = new Ailia.AILIAShape();
1000  uint id = 0;
1001  int status = Status = Ailia.ailiaFindBlobIndexByName(ailia, ref id, layer_name);
1002  if (status != Ailia.AILIA_STATUS_SUCCESS)
1003  {
1004  if (logging)
1005  {
1006  Debug.Log("ailiaFindBlobIndexByName failed " + status + " (" + GetStatusString(status) + ")");
1007  }
1008  return null;
1009  }
1010  status = Status = Ailia.ailiaGetBlobShape(ailia, shape, id, Ailia.AILIA_SHAPE_VERSION);
1011  if (status != Ailia.AILIA_STATUS_SUCCESS)
1012  {
1013  if (logging)
1014  {
1015  Debug.Log("ailiaGetBlobShape failed " + status + " (" + GetStatusString(status) + ")");
1016  }
1017  return null;
1018  }
1019  return shape;
1020  }

◆ 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.

1073  {
1074  if (ailia == IntPtr.Zero)
1075  {
1076  return null;
1077  }
1078 
1079  Ailia.AILIAShape shape = new Ailia.AILIAShape();
1080  int status = Status = Ailia.ailiaGetBlobShape(ailia, shape, idx, Ailia.AILIA_SHAPE_VERSION);
1081  if (status != Ailia.AILIA_STATUS_SUCCESS)
1082  {
1083  if (logging)
1084  {
1085  Debug.Log("ailiaGetBlobShape failed " + status + " (" + GetStatusString(status) + ")");
1086  }
1087  return null;
1088  }
1089  return shape;
1090  }

◆ 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.

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

◆ 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.

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

◆ 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.
1603  {
1604  return Marshal.PtrToStringAnsi(Ailia.ailiaGetErrorDetail(ailia));
1605  }

◆ 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.
1367  {
1368  if (ailia == IntPtr.Zero)
1369  {
1370  return null;
1371  }
1372 
1373  uint count = 0;
1374  int status = Status = Ailia.ailiaGetInputBlobCount(ailia, ref count);
1375  if (status != Ailia.AILIA_STATUS_SUCCESS || count == 0)
1376  {
1377  return null;
1378  }
1379 
1380  uint[] r = new uint[count];
1381  for (uint i = 0; i < count; i++)
1382  {
1383  uint idx = 0;
1384  status = Status = Ailia.ailiaGetBlobIndexByInputIndex(ailia, ref idx, i);
1385  if (status != Ailia.AILIA_STATUS_SUCCESS)
1386  {
1387  break;
1388  }
1389  r[i] = idx;
1390  }
1391 
1392  return r;
1393  }

◆ GetInputShape()

Ailia.AILIAShape ailia.AiliaModel.GetInputShape ( )
inline
740  {
741  Ailia.AILIAShape shape = new Ailia.AILIAShape();
742  int status = Status = Ailia.ailiaGetInputShape(ailia, shape, Ailia.AILIA_SHAPE_VERSION);
743  if (status != Ailia.AILIA_STATUS_SUCCESS)
744  {
745  if (logging)
746  {
747  Debug.Log("ailiaGetInputShape failed " + status + " (" + GetStatusString(status) + ")");
748  }
749  return null;
750  }
751  return shape;
752  }

◆ 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.
779  {
780  uint dim = 0;
781  int status = Status = Ailia.ailiaGetInputDim(ailia, ref dim);
782  if (status != Ailia.AILIA_STATUS_SUCCESS)
783  {
784  if (logging)
785  {
786  Debug.Log("ailiaGetInputDim failed " + status + " (" + GetStatusString(status) + ")");
787  }
788  return null;
789  }
790  uint[] shape = new uint[dim];
791  status = Status = Ailia.ailiaGetInputShapeND(ailia, shape, dim);
792  if (status != Ailia.AILIA_STATUS_SUCCESS)
793  {
794  if (logging)
795  {
796  Debug.Log("ailiaGetInputShapeND failed " + status + " (" + GetStatusString(status) + ")");
797  }
798  return null;
799  }
800  return shape;
801  }

◆ 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.
1413  {
1414  if (ailia == IntPtr.Zero)
1415  {
1416  return null;
1417  }
1418 
1419  uint count = 0;
1420  int status = Status = Ailia.ailiaGetOutputBlobCount(ailia, ref count);
1421  if (status != Ailia.AILIA_STATUS_SUCCESS || count == 0)
1422  {
1423  return null;
1424  }
1425 
1426  uint[] r = new uint[count];
1427  for (uint i = 0; i < count; i++)
1428  {
1429  uint idx = 0;
1430  status = Status = Ailia.ailiaGetBlobIndexByOutputIndex(ailia, ref idx, i);
1431  if (status != Ailia.AILIA_STATUS_SUCCESS)
1432  {
1433  break;
1434  }
1435  r[i] = idx;
1436  }
1437  return r;
1438  }

◆ 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().

912  {
913  if (ailia == IntPtr.Zero)
914  {
915  return null;
916  }
917  Ailia.AILIAShape shape = new Ailia.AILIAShape();
918  int status = Status = Ailia.ailiaGetOutputShape(ailia, shape, Ailia.AILIA_SHAPE_VERSION);
919  if (status != Ailia.AILIA_STATUS_SUCCESS)
920  {
921  if (logging)
922  {
923  Debug.Log("ailiaGetOutputShape failed " + status + " (" + GetStatusString(status) + ")");
924  }
925  return null;
926  }
927  return shape;
928  }

◆ 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.

948  {
949  uint dim = 0;
950  int status = Status = Ailia.ailiaGetOutputDim(ailia, ref dim);
951  if (status != Ailia.AILIA_STATUS_SUCCESS)
952  {
953  if (logging)
954  {
955  Debug.Log("ailiaGetOutputDim failed " + status + " (" + GetStatusString(status) + ")");
956  }
957  return null;
958  }
959  uint[] shape = new uint[dim];
960  status = Status = Ailia.ailiaGetOutputShapeND(ailia, shape, dim);
961  if (status != Ailia.AILIA_STATUS_SUCCESS)
962  {
963  if (logging)
964  {
965  Debug.Log("ailiaGetOutputShapeND failed " + status + " (" + GetStatusString(status) + ")");
966  }
967  return null;
968  }
969  return shape;
970  }

◆ 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.

222  {
223  IntPtr env_ptr = IntPtr.Zero;
224  int status = Status = Ailia.ailiaGetSelectedEnvironment(ailia, ref env_ptr, Ailia.AILIA_ENVIRONMENT_VERSION);
225  if (status != Ailia.AILIA_STATUS_SUCCESS)
226  {
227  if (logging)
228  {
229  Debug.Log("ailiaGetSelectedEnvironment failed " + status + " (" + GetStatusString(status) + ")");
230  }
231  return null;
232  }
233  Ailia.AILIAEnvironment env = (Ailia.AILIAEnvironment)Marshal.PtrToStructure(env_ptr, typeof(Ailia.AILIAEnvironment));
234  return env;
235  }

◆ 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.
1582  {
1583  return Marshal.PtrToStringAnsi(Ailia.ailiaGetStatusString(status));
1584  }

◆ 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.
1669  {
1670  uint buffer_size = 0;
1671  int status = Status = Ailia.ailiaGetSummaryLength(ailia, ref buffer_size);
1672  if (status != Ailia.AILIA_STATUS_SUCCESS)
1673  {
1674  if (logging)
1675  {
1676  Debug.Log("ailiaGetSummaryLength failed " + status + " (" + GetStatusString(status) + ")");
1677  }
1678  return null;
1679  }
1680  byte[] buffer = new byte[buffer_size];
1681  status = Status = Ailia.ailiaSummary(ailia, buffer, buffer_size);
1682  if (status != Ailia.AILIA_STATUS_SUCCESS)
1683  {
1684  if (logging)
1685  {
1686  Debug.Log("ailiaSummary failed " + status + " (" + GetStatusString(status) + ")");
1687  }
1688  return null;
1689  }
1690  return System.Text.Encoding.ASCII.GetString(buffer);
1691  }

◆ 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.

584  {
585  Close();
586 
587  int status = Status = Ailia.ailiaCreate(ref ailia, env_id, Ailia.AILIA_MULTITHREAD_AUTO);
588  if (status != Ailia.AILIA_STATUS_SUCCESS)
589  {
590  DisplayLicenseError(status);
591  if (logging)
592  {
593  Debug.Log("ailiaCreate failed " + status + " (" + GetStatusString(status) + ")");
594  }
595  return false;
596  }
597 
598  if (memory_mode != Ailia.AILIA_MEMORY_OPTIMAIZE_DEFAULT)
599  {
600  status = Status = Ailia.ailiaSetMemoryMode(ailia, memory_mode);
601  if (status != Ailia.AILIA_STATUS_SUCCESS)
602  {
603  if (logging)
604  {
605  Debug.Log("ailiaSetMemoryMode failed " + status + " (" + GetStatusString(status) + ")");
606  }
607  Close();
608  return false;
609  }
610  }
611  if (disalbe_layer_fusion)
612  {
613  status = Status = Ailia.ailiaDisableLayerFusion(ailia);
614  if (status != Ailia.AILIA_STATUS_SUCCESS)
615  {
616  if (logging)
617  {
618  Debug.Log("ailiaDisableLayerFusion failed " + status + " (" + GetStatusString(status) + ")");
619  }
620  Close();
621  return false;
622  }
623  }
624 
625  if (arg1 != null)
626  {
627  status = Status = Ailia.ailiaOpenStreamEx(ailia, arg1, callback, Ailia.AILIA_FILE_CALLBACK_VERSION);
628  if (status != Ailia.AILIA_STATUS_SUCCESS)
629  {
630  if (logging)
631  {
632  Debug.Log("ailiaOpenStreamFileEx failed " + status + " (" + GetStatusString(status) + ")");
633  }
634  Close();
635  return false;
636  }
637  }
638 
639  status = Status = Ailia.ailiaOpenWeightEx(ailia, arg2, callback, Ailia.AILIA_FILE_CALLBACK_VERSION);
640  if (status != Ailia.AILIA_STATUS_SUCCESS)
641  {
642  if (logging)
643  {
644  Debug.Log("ailiaOpenWeightFileEx failed " + status + " (" + GetStatusString(status) + ")");
645  }
646  Close();
647  return false;
648  }
649 
650  return true;
651  }

◆ 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.

386  {
387  Close();
388 
389  int status = Status = Ailia.ailiaCreate(ref ailia, env_id, Ailia.AILIA_MULTITHREAD_AUTO);
390  if (status != Ailia.AILIA_STATUS_SUCCESS)
391  {
392  DisplayLicenseError(status);
393  if (logging)
394  {
395  Debug.Log("ailiaCreate failed " + status + " (" + GetStatusString(status) + ")");
396  }
397  return false;
398  }
399 
400  if (memory_mode != Ailia.AILIA_MEMORY_OPTIMAIZE_DEFAULT)
401  {
402  status = Status = Ailia.ailiaSetMemoryMode(ailia, memory_mode);
403  if (status != Ailia.AILIA_STATUS_SUCCESS)
404  {
405  if (logging)
406  {
407  Debug.Log("ailiaSetMemoryMode failed " + status + " (" + GetStatusString(status) + ")");
408  }
409  Close();
410  return false;
411  }
412  }
413  if (disalbe_layer_fusion)
414  {
415  status = Status = Ailia.ailiaDisableLayerFusion(ailia);
416  if (status != Ailia.AILIA_STATUS_SUCCESS)
417  {
418  if (logging)
419  {
420  Debug.Log("ailiaDisableLayerFusion failed " + status + " (" + GetStatusString(status) + ")");
421  }
422  Close();
423  return false;
424  }
425  }
426 
427  if (prototxt_path != null)
428  {
429  status = Status = Ailia.ailiaOpenStreamFile(ailia, prototxt_path);
430  if (status != Ailia.AILIA_STATUS_SUCCESS)
431  {
432  if (logging)
433  {
434  Debug.Log("ailiaOpenStreamFile failed " + status + " (" + GetStatusString(status) + ")");
435  }
436  Close();
437  return false;
438  }
439  }
440 
441  status = Status = Ailia.ailiaOpenWeightFile(ailia, model_path);
442  if (status != Ailia.AILIA_STATUS_SUCCESS)
443  {
444  if (logging)
445  {
446  Debug.Log("ailiaOpenWeightFile failed " + status + " (" + GetStatusString(status) + ")");
447  }
448  Close();
449  return false;
450  }
451 
452  return true;
453  }

◆ 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.

479  {
480  Close();
481 
482  if (model_buf == null || model_buf.Length == 0 || (prototxt_buf != null && prototxt_buf.Length == 0))
483  {
484  if (logging)
485  {
486  Debug.Log("input buffer is empty");
487  }
488  return false;
489  }
490 
491  int status = Status = Ailia.ailiaCreate(ref ailia, env_id, Ailia.AILIA_MULTITHREAD_AUTO);
492  if (status != Ailia.AILIA_STATUS_SUCCESS)
493  {
494  DisplayLicenseError(status);
495  if (logging)
496  {
497  Debug.Log("ailiaCreate failed " + status + " (" + GetStatusString(status) + ")");
498  }
499  return false;
500  }
501 
502  if (memory_mode != Ailia.AILIA_MEMORY_OPTIMAIZE_DEFAULT)
503  {
504  status = Status = Ailia.ailiaSetMemoryMode(ailia, memory_mode);
505  if (status != Ailia.AILIA_STATUS_SUCCESS)
506  {
507  if (logging)
508  {
509  Debug.Log("ailiaSetMemoryMode failed " + status + " (" + GetStatusString(status) + ")");
510  }
511  Close();
512  return false;
513  }
514  }
515  if (disalbe_layer_fusion)
516  {
517  status = Status = Ailia.ailiaDisableLayerFusion(ailia);
518  if (status != Ailia.AILIA_STATUS_SUCCESS)
519  {
520  if (logging)
521  {
522  Debug.Log("ailiaDisableLayerFusion failed " + status + " (" + GetStatusString(status) + ")");
523  }
524  Close();
525  return false;
526  }
527  }
528 
529  if (prototxt_buf != null)
530  {
531  status = Status = Ailia.ailiaOpenStreamMem(ailia, prototxt_buf, (uint)prototxt_buf.Length);
532  if (status != Ailia.AILIA_STATUS_SUCCESS)
533  {
534  if (logging)
535  {
536  Debug.Log("ailiaOpenStreamMem failed " + status + " (" + GetStatusString(status) + ")");
537  }
538  Close();
539  return false;
540  }
541  }
542 
543  status = Status = Ailia.ailiaOpenWeightMem(ailia, model_buf, (uint)model_buf.Length);
544  if (status != Ailia.AILIA_STATUS_SUCCESS)
545  {
546  if (logging)
547  {
548  Debug.Log("ailiaOpenWeightMem filed " + status + " (" + GetStatusString(status) + ")");
549  }
550  Close();
551  return false;
552  }
553 
554  return true;
555  }

◆ 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.
682  {
683  if (ailia == IntPtr.Zero)
684  {
685  return false;
686  }
687 
688  //バッファの固定
689  GCHandle input_buf_handle = GCHandle.Alloc(input_data, GCHandleType.Pinned);
690  IntPtr input_buf_ptr = input_buf_handle.AddrOfPinnedObject();
691 
692  GCHandle output_buf_handle = GCHandle.Alloc(output_data, GCHandleType.Pinned);
693  IntPtr output_buf_ptr = output_buf_handle.AddrOfPinnedObject();
694 
695  //推論
696  int status = Status = Ailia.ailiaPredict(ailia, output_buf_ptr, (uint)(output_data.Length * 4), input_buf_ptr, (uint)(input_data.Length * 4));
697 
698  //バッファの開放
699  input_buf_handle.Free();
700  output_buf_handle.Free();
701 
702  if (status != Ailia.AILIA_STATUS_SUCCESS)
703  {
704  if (logging)
705  {
706  Debug.Log("ailiaPredict failed " + status + " (" + GetStatusString(status) + ")");
707  }
708  return false;
709  }
710  return true;
711  }

◆ 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.

195  {
196  Ailia.AILIAEnvironment env = GetEnvironment(idx);
197  if (env == null)
198  {
199  return false;
200  }
201  env_id = env.id;
202  env_name = Marshal.PtrToStringAnsi(env.name);
203  return true;
204  }

◆ 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.

1218  {
1219  if (ailia == IntPtr.Zero || idx < 0)
1220  {
1221  return false;
1222  }
1223  return SetInputBlobData(input_data, (uint)idx);
1224  }
bool SetInputBlobData(float[] input_data, uint idx)
Set input data to the specified Blob.
Definition: AiliaModel.cs:1187

◆ 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.

1188  {
1189  if (ailia == IntPtr.Zero)
1190  {
1191  return false;
1192  }
1193 
1194  GCHandle input_buf_handle = GCHandle.Alloc(input_data, GCHandleType.Pinned);
1195  IntPtr input_buf_ptr = input_buf_handle.AddrOfPinnedObject();
1196  int status = Status = Ailia.ailiaSetInputBlobData(ailia, input_buf_ptr, (uint)(input_data.Length * 4), idx);
1197  input_buf_handle.Free();
1198 
1199  if (status != Ailia.AILIA_STATUS_SUCCESS)
1200  {
1201  if (logging)
1202  {
1203  Debug.Log("ailiaSetInputBlobData failed " + status + " (" + GetStatusString(status) + ")");
1204  }
1205  return false;
1206  }
1207  return true;
1208  }

◆ 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.

1280  {
1281  if (idx < 0)
1282  {
1283  return false;
1284  }
1285  return SetInputBlobShape(shape, (uint)idx);
1286  }
bool SetInputBlobShape(Ailia.AILIAShape shape, uint idx)
Sets the format of the specified input data (Blob). (4 dimensions or less)
Definition: AiliaModel.cs:1253

◆ 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().
1254  {
1255  if (ailia == IntPtr.Zero)
1256  {
1257  return false;
1258  }
1259 
1260  int status = Status = Ailia.ailiaSetInputBlobShape(ailia, shape, idx, Ailia.AILIA_SHAPE_VERSION);
1261  if (status != Ailia.AILIA_STATUS_SUCCESS)
1262  {
1263  if (logging)
1264  {
1265  Debug.Log("ailiaSetInputBlobShape failed " + status + " (" + GetStatusString(status) + ")");
1266  }
1267  return false;
1268  }
1269  return true;
1270  }

◆ 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.

1338  {
1339  if (idx < 0 || dim < 0)
1340  {
1341  return false;
1342  }
1343  return SetInputBlobShapeND(shape, (uint)dim, (uint)idx);
1344  }
bool SetInputBlobShapeND(uint[] shape, uint dim, uint idx)
Sets the format of the input data (Blob). (5D or more)
Definition: AiliaModel.cs:1311

◆ 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().
1312  {
1313  if (ailia == IntPtr.Zero)
1314  {
1315  return false;
1316  }
1317 
1318  int status = Status = Ailia.ailiaSetInputBlobShapeND(ailia, shape, dim, idx);
1319  if (status != Ailia.AILIA_STATUS_SUCCESS)
1320  {
1321  if (logging)
1322  {
1323  Debug.Log("ailiaSetInputBlobShapeND failed " + status + " (" + GetStatusString(status) + ")");
1324  }
1325  return false;
1326  }
1327  return true;
1328  }

◆ 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().
831  {
832  if (ailia == IntPtr.Zero)
833  {
834  return false;
835  }
836 
837  int status = Status = Ailia.ailiaSetInputShape(ailia, shape, Ailia.AILIA_SHAPE_VERSION);
838  if (status != Ailia.AILIA_STATUS_SUCCESS)
839  {
840  if (logging)
841  {
842  Debug.Log("ailiaSetInputShape failed " + status + " (" + GetStatusString(status) + ")");
843  }
844  return false;
845  }
846  return true;
847  }

◆ 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.

875  {
876  if (ailia == IntPtr.Zero || dim < 0)
877  {
878  return false;
879  }
880 
881  int status = Status = Ailia.ailiaSetInputShapeND(ailia, shape, (uint)dim);
882  if (status != Ailia.AILIA_STATUS_SUCCESS)
883  {
884  if (logging)
885  {
886  Debug.Log("ailiaSetInputShapeND failed " + status + " (" + GetStatusString(status) + ")");
887  }
888  return false;
889  }
890  return true;
891  }

◆ SetMemoryMode()

void 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
no return value

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.

342  {
343  memory_mode = set_memory_mode;
344  }

◆ 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.
1638  {
1639  int status = Status = Ailia.ailiaSetProfileMode(ailia, profile_mode);
1640  if (status != Ailia.AILIA_STATUS_SUCCESS)
1641  {
1642  if (logging)
1643  {
1644  Debug.Log("ailiaSetProfileMode failed " + status + " (" + GetStatusString(status) + ")");
1645  }
1646  return false;
1647  }
1648  return true;
1649  }

◆ 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().
1497  {
1498  if (ailia == IntPtr.Zero)
1499  {
1500  return false;
1501  }
1502  int status = Status = Ailia.ailiaUpdate(ailia);
1503  if (status != Ailia.AILIA_STATUS_SUCCESS)
1504  {
1505  if (logging)
1506  {
1507  Debug.Log("ailiaUpdate failed " + status + " (" + GetStatusString(status) + ")");
1508  }
1509  return false;
1510  }
1511  return true;
1512  }

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.

1619 { get; protected set; }

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