public Ailia.AILIAShape GetBlobShape(string layer_name) { if (ailia == IntPtr.Zero) { return(null); } Ailia.AILIAShape shape = new Ailia.AILIAShape(); uint id = 0; int status = Ailia.ailiaFindBlobIndexByName(ailia, ref id, layer_name); if (status != Ailia.AILIA_STATUS_SUCCESS) { if (logging) { Debug.Log("ailiaFindBlobIndexByName failed" + status); } return(null); } status = Ailia.ailiaGetBlobShape(ailia, shape, id, Ailia.AILIA_SHAPE_VERSION); if (status != Ailia.AILIA_STATUS_SUCCESS) { if (logging) { Debug.Log("ailiaGetBlobShape failed" + status); } return(null); } return(shape); }
//入力形式の取得 public Ailia.AILIAShape GetInputShape() { Ailia.AILIAShape shape = new Ailia.AILIAShape(); int status = Ailia.ailiaGetInputShape(ailia, shape, Ailia.AILIA_SHAPE_VERSION); if (status != Ailia.AILIA_STATUS_SUCCESS) { if (logging) { Debug.Log("ailiaGetInputShape failed" + status); } return(null); } return(shape); }
private float[] ComputeFromImageWithFormat(Color32[] camera, int tex_width, int tex_height, uint format) { if (ailia_feature_extractor == IntPtr.Zero) { return(null); } //特徴量のサイズを取得 Ailia.AILIAShape shape = base.GetBlobShape(base.FindBlobIndexByName(layer_name)); if (shape == null) { if (logging) { Debug.Log("GetBlobShape failed"); } return(null); } //出力先の確保 float[] output_buf = new float[shape.w * shape.z * shape.y * shape.x]; GCHandle output_handle = GCHandle.Alloc(output_buf, GCHandleType.Pinned); IntPtr output_buf_ptr = output_handle.AddrOfPinnedObject(); //バッファの固定 GCHandle preview_handle = GCHandle.Alloc(camera, GCHandleType.Pinned); IntPtr preview_buf_ptr = preview_handle.AddrOfPinnedObject(); //特徴量取得 int status = AiliaFeatureExtractor.ailiaFeatureExtractorCompute(ailia_feature_extractor, output_buf_ptr, (UInt32)output_buf.Length * 4, preview_buf_ptr, (UInt32)tex_width * 4, (UInt32)tex_width, (UInt32)tex_height, format); if (status != Ailia.AILIA_STATUS_SUCCESS) { if (logging) { Debug.Log("ailiaFeatureExtractorCompute failed " + status); } return(null); } //バッファの開放 preview_handle.Free(); output_handle.Free(); return(output_buf); }
//Blobの形式を設定 public bool SetInputBlobShape(Ailia.AILIAShape shape, int idx) { if (ailia == IntPtr.Zero || idx < 0) { return(false); } int status = Ailia.ailiaSetInputBlobShape(ailia, shape, (uint)idx, Ailia.AILIA_SHAPE_VERSION); if (status != Ailia.AILIA_STATUS_SUCCESS) { if (logging) { Debug.Log("ailiaSetInputBlobShape failed" + status); } return(false); } return(true); }
//Blobの形状を取得 public Ailia.AILIAShape GetBlobShape(int idx) { if (ailia == IntPtr.Zero || idx < 0) { return(null); } Ailia.AILIAShape shape = new Ailia.AILIAShape(); int status = Ailia.ailiaGetBlobShape(ailia, shape, (uint)idx, Ailia.AILIA_SHAPE_VERSION); if (status != Ailia.AILIA_STATUS_SUCCESS) { if (logging) { Debug.Log("ailiaGetBlobShape failed" + status); } return(null); } return(shape); }
void SetShape(ImageSegmentaionModels imageSegmentaionModels) { Ailia.AILIAShape shape = null; switch (imageSegmentaionModels) { case ImageSegmentaionModels.HRNetV2_W18_Small_v2: case ImageSegmentaionModels.HRNetV2_W18_Small_v1: case ImageSegmentaionModels.HRNetV2_W48: case ImageSegmentaionModels.pspnet_hair_segmentation: case ImageSegmentaionModels.deeplabv3: shape = ailiaModel.GetInputShape(); InputWidth = (int)shape.x; InputHeight = (int)shape.y; InputChannel = (int)shape.z; shape = ailiaModel.GetOutputShape(); OutputWidth = (int)shape.x; OutputHeight = (int)shape.y; OutputChannel = (int)shape.z; break; case ImageSegmentaionModels.hair_segmentation: shape = new Ailia.AILIAShape(); shape.x = 3; shape.y = (uint)AiliaImageSource.Width; shape.z = (uint)AiliaImageSource.Height; shape.w = 1; shape.dim = 4; ailiaModel.SetInputShape(shape); InputWidth = AiliaImageSource.Width; InputHeight = AiliaImageSource.Height; InputChannel = 3; OutputWidth = AiliaImageSource.Width; OutputHeight = AiliaImageSource.Height; OutputChannel = 1; break; } }
void SetShape(ImageManipulationModels imageSegmentaionModels) { Ailia.AILIAShape shape = null; switch (imageSegmentaionModels) { case ImageManipulationModels.SRResNet: case ImageManipulationModels.Noise2Noise: shape = ailiaModel.GetInputShape(); InputWidth = (int)shape.x; InputHeight = (int)shape.y; InputChannel = (int)shape.z; shape = ailiaModel.GetOutputShape(); OutputWidth = (int)shape.x; OutputHeight = (int)shape.y; OutputChannel = (int)shape.z; break; case ImageManipulationModels.IlluminationCorrection: shape = new Ailia.AILIAShape(); shape.x = (uint)AiliaImageSource.Width; shape.y = (uint)AiliaImageSource.Height; shape.z = 3; shape.w = 1; shape.dim = 4; ailiaModel.SetInputShape(shape); InputWidth = AiliaImageSource.Width; InputHeight = AiliaImageSource.Height; InputChannel = 3; OutputWidth = AiliaImageSource.Width; OutputHeight = AiliaImageSource.Height; OutputChannel = 3; break; #if false case ImageManipulationModels.Colorization: shape = new Ailia.AILIAShape(); shape.x = (uint)AiliaImageSource.Width; shape.y = (uint)AiliaImageSource.Height; shape.z = 1; shape.w = 1; shape.dim = 4; ailiaModel.SetInputShape(shape); InputWidth = AiliaImageSource.Width; InputHeight = AiliaImageSource.Height; InputChannel = 1; OutputWidth = AiliaImageSource.Width; OutputHeight = AiliaImageSource.Height; OutputChannel = 2; break; #else // 256x256に縮小してみる case ImageManipulationModels.Colorization: shape = ailiaModel.GetInputShape(); shape.z = 1; shape.w = 1; shape.dim = 4; ailiaModel.SetInputShape(shape); InputWidth = (int)shape.x; InputHeight = (int)shape.y; InputChannel = 1; OutputWidth = InputWidth; // AiliaImageSource.Width; OutputHeight = InputHeight; // AiliaImageSource.Height; OutputChannel = 2; break; #endif // ~true } }