ailia  1.3.0.0
Public Member Functions | Protected Member Functions | List of all members
AiliaFeatureExtractorModel Class Reference
Inheritance diagram for AiliaFeatureExtractorModel:
Inheritance graph
[legend]
Collaboration diagram for AiliaFeatureExtractorModel:
Collaboration graph
[legend]

Public Member Functions

bool Settings (uint set_format, uint set_channel, uint set_range, uint set_distance_type, string set_layer_name)
 Model setting. More...
 
override bool OpenFile (string prototxt, string model_path)
 Create a network object from a model file. More...
 
override bool OpenEx (Ailia.ailiaFileCallback callback, IntPtr arg1, IntPtr arg2)
 Creates a network object from a file callback. More...
 
override bool OpenMem (byte[] prototxt_buf, byte[] model_buf)
 Creates network objects from memory. More...
 
float [] ComputeFromImage (Color32 [] image, int image_width, int image_height)
 Acquire features from images. More...
 
float [] ComputeFromImageB2T (Color32 [] image, int image_width, int image_height)
 Obtain features from the upside-down image. More...
 
float Match (float [] feature1, float [] feature2)
 Calculates the distance between features. More...
 
override void Close ()
 Destroy feature extraction quobjects. More...
 
override void Dispose ()
 Release resources. More...
 
- Public Member Functions inherited from AiliaModel
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...
 
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...
 
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

override void Dispose (bool disposing)
 

Additional Inherited Members

- Protected Attributes inherited from AiliaModel
IntPtr ailia = IntPtr.Zero
 
bool logging = true
 
- Properties inherited from AiliaModel
int Status [get, protected set]
 Status code Get the library status code. More...
 

Member Function Documentation

◆ Close()

override void AiliaFeatureExtractorModel.Close ( )
inlinevirtual

Destroy feature extraction quobjects.

Returns
Return nothing.

Destroys the feature extractor object.

Reimplemented from AiliaModel.

355  {
356  if(ailia_feature_extractor!=IntPtr.Zero){
357  AiliaFeatureExtractor.ailiaDestroyFeatureExtractor(ailia_feature_extractor);
358  ailia_feature_extractor=IntPtr.Zero;
359  }
360  base.Close();
361  }
static void ailiaDestroyFeatureExtractor(IntPtr fextractor)
Destroy feature extractor object.
Definition: AiliaFeatureExtractor.cs:20

◆ ComputeFromImage()

float [] AiliaFeatureExtractorModel.ComputeFromImage ( Color32 []  image,
int  image_width,
int  image_height 
)
inline

Acquire features from images.

Parameters
imageImage to be extraction
image_widthImage width
image_heightImage height
Returns
Feature vector

Calculate feature vectors from images.

198  {
199  return ComputeFromImageWithFormat(image,image_width,image_height,AiliaFormat.AILIA_IMAGE_FORMAT_RGBA);
200  }
Definition: AiliaFormat.cs:20
const Int32 AILIA_IMAGE_FORMAT_RGBA
Definition: AiliaFormat.cs:33

◆ ComputeFromImageB2T()

float [] AiliaFeatureExtractorModel.ComputeFromImageB2T ( Color32 []  image,
int  image_width,
int  image_height 
)
inline

Obtain features from the upside-down image.

Parameters
imageImage to be extraction
image_widthImage width
image_heightImage height
Returns
Feature vector

Calculate feature vectors from images.

224  {
225  return ComputeFromImageWithFormat(image,image_width,image_height,AiliaFormat.AILIA_IMAGE_FORMAT_RGBA_B2T);
226  }
Definition: AiliaFormat.cs:20
const Int32 AILIA_IMAGE_FORMAT_RGBA_B2T
Definition: AiliaFormat.cs:50

◆ Dispose() [1/2]

override void AiliaFeatureExtractorModel.Dispose ( )
inlinevirtual

Release resources.

Reimplemented from AiliaModel.

371  {
372  Dispose(true);
373  }
override void Dispose()
Release resources.
Definition: AiliaFeatureExtractorModel.cs:370

◆ Dispose() [2/2]

override void AiliaFeatureExtractorModel.Dispose ( bool  disposing)
inlineprotectedvirtual

Reimplemented from AiliaModel.

376  {
377  if (disposing){
378  // release managed resource
379  }
380  Close(); // release unmanaged resource
381  base.Dispose(disposing);
382  }
override void Close()
Destroy feature extraction quobjects.
Definition: AiliaFeatureExtractorModel.cs:355

◆ Match()

float AiliaFeatureExtractorModel.Match ( float []  feature1,
float []  feature2 
)
inline

Calculates the distance between features.

Parameters
feature1Feature 1
feature2Feature 2
Returns
Calculated Distance

Calculate the distance between feature 1 and feature 2.

310  {
311  if(feature1==null || feature2==null){
312  if(logging){
313  Debug.Log("input feature is empty");
314  }
315  return float.NaN;
316  }
317 
318  float distance=0;
319 
320  GCHandle feature1_handle = GCHandle.Alloc(feature1, GCHandleType.Pinned);
321  IntPtr feature1_buf_ptr = feature1_handle.AddrOfPinnedObject();
322 
323  GCHandle feature2_handle = GCHandle.Alloc(feature2, GCHandleType.Pinned);
324  IntPtr feature2_buf_ptr = feature2_handle.AddrOfPinnedObject();
325 
326  int status=AiliaFeatureExtractor.ailiaFeatureExtractorMatch(ailia_feature_extractor,ref distance, distace_type, feature1_buf_ptr, (uint)feature1.Length*4, feature2_buf_ptr, (uint)feature2.Length*4);
327  if(status!=Ailia.AILIA_STATUS_SUCCESS){
328  if(logging){
329  Debug.Log("ailiaFeatureExtractorMatch failed "+status);
330  }
331  return float.NaN;
332  }
333 
334  feature1_handle.Free();
335  feature2_handle.Free();
336  return distance;
337  }
bool logging
Definition: AiliaModel.cs:32
static int ailiaFeatureExtractorMatch(IntPtr fextractor, ref float distance, UInt32 distace_type, IntPtr feature1, UInt32 feature1_size, IntPtr feature2, UInt32 feature2_size)
Calculate the distance between features.
Definition: Ailia.cs:20
Definition: AiliaFeatureExtractor.cs:20
const Int32 AILIA_STATUS_SUCCESS
Definition: Ailia.cs:34

◆ OpenEx()

override bool AiliaFeatureExtractorModel.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
alg1Argument pointer notified to AILIA_USER_API_FOPEN
alg2Argument pointer notified to AILIA_USER_API_FOPEN
Returns
If this function is successful, it returns true , or false otherwise.

Creates a network object from a file callback.

Reimplemented from AiliaModel.

120  {
121  Close();
122  bool status=base.OpenEx(callback,arg1,arg2);
123  if(status==false){
124  if(logging){
125  Debug.Log("ailiaModelOpenEx failed");
126  }
127  return false;
128  }
129  return OpenFeatureExtractor();
130  }
bool logging
Definition: AiliaModel.cs:32
override void Close()
Destroy feature extraction quobjects.
Definition: AiliaFeatureExtractorModel.cs:355

◆ OpenFile()

override bool AiliaFeatureExtractorModel.OpenFile ( string  prototxt,
string  model_path 
)
inlinevirtual

Create a network object from a model file.

Parameters
prototxtPath name of the prototxt file (MBSC or UTF16)
model_pathPathname of the protobuf/onnx file (MBSC or UTF16)
Returns
If this function is successful, it returns true , or false otherwise.

Create a network object from a model file.

Reimplemented from AiliaModel.

86  {
87  Close();
88  bool status=base.OpenFile(prototxt,model_path);
89  if(status==false){
90  if(logging){
91  Debug.Log("ailiaModelOpenFile failed");
92  }
93  return false;
94  }
95  return OpenFeatureExtractor();
96  }
bool logging
Definition: AiliaModel.cs:32
override void Close()
Destroy feature extraction quobjects.
Definition: AiliaFeatureExtractorModel.cs:355

◆ OpenMem()

override bool AiliaFeatureExtractorModel.OpenMem ( byte []  prototxt_buf,
byte []  model_buf 
)
inlinevirtual

Creates network objects from memory.

Parameters
prototxtPointer to data in prototxt file
model_pathPointer to data in protobuf/onnx file
Returns
If this function is successful, it returns true , or false otherwise.

Creates network objects from memory.

Reimplemented from AiliaModel.

152  {
153  Close();
154  bool status=base.OpenMem(prototxt_buf,model_buf);
155  if(status==false){
156  if(logging){
157  Debug.Log("ailiaModelOpenMem failed");
158  }
159  return false;
160  }
161  return OpenFeatureExtractor();
162  }
bool logging
Definition: AiliaModel.cs:32
override void Close()
Destroy feature extraction quobjects.
Definition: AiliaFeatureExtractorModel.cs:355

◆ Settings()

bool AiliaFeatureExtractorModel.Settings ( uint  set_format,
uint  set_channel,
uint  set_range,
uint  set_distance_type,
string  set_layer_name 
)
inline

Model setting.

Parameters
set_formatThe network image format (AILIA_NETWORK_IMAGE_FORMAT_*)
set_channelThe network image channel (AILIA_NETWORK_IMAGE_CHANNEL_*)
set_rangeThe network image range (AILIA_NETWORK_IMAGE_RANGE_*)
set_distance_typeThe type of the distance in feature space
set_layer_nameThe name of the layer corresponding to the feature (fc1 for VGG16 and NULL for the last layer)
Returns
Returns true on success.

Pre-process images of the network and set up distance calculations.

57  {
58  format=set_format;
59  channel=set_channel;
60  range=set_range;
61  distace_type=set_distance_type;
62  layer_name=set_layer_name;
63  return true;
64  }

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