0
votes

I want to convert this NSFW model to CoreML model. What I did:

  1. Download Anaconda 2.7
  2. Install coremltools
  3. Convert this yahoo nsfw model from here - https://github.com/yahoo/open_nsfw/tree/master/nsfw_model but I am not sure it’s Caffe v1 because Apple documentation says that only this version supported. Anyway…
  4. I use this commands for conversion and it converted without any warnings.

    coreml_model = coremltools.converters.caffe.convert(('resnet_50_1by2_nsfw.caffemodel', 'deploy.prototxt'), image_input_names='data') coreml_model.save(’nsfw2.mlmodel')

  5. I imported this model to my project and again all looks fine.
  6. I prepared 224x224 images and use Vision framework like VNImageRequestHandler with cgImage and etc.

But!

All images return the same result

[<VNCoreMLFeatureValueObservation: 0x281b1daa0> 2E00F417-95C0-4AA1-A621-A0945BB5E095 requestRevision=1 confidence=1.000000 "prob" - "MultiArray : Double 1 x 1 x 2 x 1 x 1 array" (1.000000)]

How can I debug this issue and found out what’s wrong?

enter image description here

1

1 Answers

0
votes

Maybe you're looking only at naughty images? ;-)

It's probably the image preprocessing. You didn't specify any preprocessing options while Caffe models usually normalize using ImageNet mean/std. Refer to my blog post for more info: https://machinethink.net/blog/help-core-ml-gives-wrong-output/

However, I don't see any normalization options in your deploy.prototxt, so perhaps it's not that.

How I would debug this: remove everything but the first layer from the Caffe model and convert to Core ML. Run this one-layer model in both Caffe and Core ML and compare the outputs. If they are different, something is up with how you're loading or preprocessing the input data.