ailia  1.6.0.0
Public Member Functions | Protected Member Functions | List of all members
ailia.AiliaFeatureExtractorModel Class Reference
Inheritance diagram for ailia.AiliaFeatureExtractorModel:
Inheritance graph
[legend]
Collaboration diagram for ailia.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 ailia.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...
 
bool SetMemoryMode (uint set_memory_mode)
 Sets the memory mode. More...
 
bool 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 ailia.AiliaModel
IntPtr ailia = IntPtr.Zero
 
bool logging = true
 
- Properties inherited from ailia.AiliaModel
int Status [get, protected set]
 Status code @detail Get the library status code. More...
 

Member Function Documentation

◆ Close()

override void ailia.AiliaFeatureExtractorModel.Close ( )
inlinevirtual

Destroy feature extraction quobjects.

Returns
Return nothing.

Destroys the feature extractor object.

Reimplemented from ailia.AiliaModel.

365  {
366  if(ailia_feature_extractor!=IntPtr.Zero){
367  AiliaFeatureExtractor.ailiaDestroyFeatureExtractor(ailia_feature_extractor);
368  ailia_feature_extractor=IntPtr.Zero;
369  }
370  base.Close();
371  }

◆ ComputeFromImage()

float [] ailia.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.

208  {
209  return ComputeFromImageWithFormat(image,image_width,image_height,AiliaFormat.AILIA_IMAGE_FORMAT_RGBA);
210  }

◆ ComputeFromImageB2T()

float [] ailia.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.

234  {
235  return ComputeFromImageWithFormat(image,image_width,image_height,AiliaFormat.AILIA_IMAGE_FORMAT_RGBA_B2T);
236  }

◆ Dispose() [1/2]

override void ailia.AiliaFeatureExtractorModel.Dispose ( )
inlinevirtual

Release resources.

Reimplemented from ailia.AiliaModel.

381  {
382  Dispose(true);
383  }
override void Dispose()
Release resources.
Definition: AiliaFeatureExtractorModel.cs:380

◆ Dispose() [2/2]

override void ailia.AiliaFeatureExtractorModel.Dispose ( bool  disposing)
inlineprotectedvirtual

Reimplemented from ailia.AiliaModel.

386  {
387  if (disposing){
388  // release managed resource
389  }
390  Close(); // release unmanaged resource
391  base.Dispose(disposing);
392  }
override void Close()
Destroy feature extraction quobjects.
Definition: AiliaFeatureExtractorModel.cs:365

◆ Match()

float ailia.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.

320  {
321  if(feature1==null || feature2==null){
322  if(logging){
323  Debug.Log("input feature is empty");
324  }
325  return float.NaN;
326  }
327 
328  float distance=0;
329 
330  GCHandle feature1_handle = GCHandle.Alloc(feature1, GCHandleType.Pinned);
331  IntPtr feature1_buf_ptr = feature1_handle.AddrOfPinnedObject();
332 
333  GCHandle feature2_handle = GCHandle.Alloc(feature2, GCHandleType.Pinned);
334  IntPtr feature2_buf_ptr = feature2_handle.AddrOfPinnedObject();
335 
336  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);
337  if(status!=Ailia.AILIA_STATUS_SUCCESS){
338  if(logging){
339  Debug.Log("ailiaFeatureExtractorMatch failed "+status);
340  }
341  return float.NaN;
342  }
343 
344  feature1_handle.Free();
345  feature2_handle.Free();
346  return distance;
347  }
bool logging
Definition: AiliaModel.cs:33

◆ OpenEx()

override bool ailia.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 ailia.AiliaModel.

130  {
131  Close();
132  bool status=base.OpenEx(callback,arg1,arg2);
133  if(status==false){
134  if(logging){
135  Debug.Log("ailiaModelOpenEx failed");
136  }
137  return false;
138  }
139  return OpenFeatureExtractor();
140  }

◆ OpenFile()

override bool ailia.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 ailia.AiliaModel.

96  {
97  Close();
98  bool status=base.OpenFile(prototxt,model_path);
99  if(status==false){
100  if(logging){
101  Debug.Log("ailiaModelOpenFile failed");
102  }
103  return false;
104  }
105  return OpenFeatureExtractor();
106  }

◆ OpenMem()

override bool ailia.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 ailia.AiliaModel.

162  {
163  Close();
164  bool status=base.OpenMem(prototxt_buf,model_buf);
165  if(status==false){
166  if(logging){
167  Debug.Log("ailiaModelOpenMem failed");
168  }
169  return false;
170  }
171  return OpenFeatureExtractor();
172  }

◆ Settings()

bool ailia.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.

Remarks
This method will no effect (always retun false) after call OpenXXX Method.
62  {
63  if (ailia_feature_extractor != IntPtr.Zero)
64  {
65  Debug.Assert(false, "Ailia Feature Extractor is already initialized.");
66  return false;
67  }
68  format=set_format;
69  channel=set_channel;
70  range=set_range;
71  distace_type=set_distance_type;
72  layer_name=set_layer_name;
73  return true;
74  }

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