/// <summary> /// Constructs a new image classifier instance from the caffe model in memory. /// </summary> /// <param name="prototxt"> /// The prototxt data. /// </param> /// <param name="model"> /// The model data. /// </param> /// <param name="type"> /// The type of classifier to create. /// </param> /// <param name="mean"> /// The optional mean value for the supplied model. Internally, defaults to the predefined /// mean for the built in models (resnet 50, squeezenet). /// </param> public ImageClassifier(byte[] prototxt, byte[] model, ClassifierType type, double[] mean = null) { IntPtr meanPtr = IntPtr.Zero; if (mean != null) { switch (mean.Length) { case 3: case 4: { } break; default: { throw new ArgumentException("Mean value, if supplied, must have a length of 3 or 4. BGR(A)."); } } meanPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(double)) * mean.Length); Marshal.Copy(mean, 0, meanPtr, mean.Length); } m_nativeObj = ImageClassifierPInvoke.classifier_create_from_memory(prototxt, prototxt.Length, model, model.Length, (byte)type, meanPtr); if (meanPtr != IntPtr.Zero) { Marshal.FreeHGlobal(meanPtr); } if (m_nativeObj == IntPtr.Zero) { throw new Exception("Failed to allocate native classifier."); } }