Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to convert the private-detector model to a CoreML model? #13

Open
ChouJay opened this issue Nov 16, 2023 · 2 comments
Open

Comments

@ChouJay
Copy link

ChouJay commented Nov 16, 2023

Dear Bumble tech,
I've been attempting to convert the private-detector's saved_model into a CoreML model. However, after the conversion, it seems unable to successfully identify NSFW images. I suspect there might be an issue during the conversion process. Could you guide me on how to correctly convert a saved_model.pb into a CoreML .mlPackage? Thanks a lot!
Here's my code:

import coremltools as ct
mlmodel_from_tf = ct.convert(model="/Path/To/private_detector/saved_model",
                           inputs=[ct.ImageType(shape=(1,480,480,3))],
                           source="tensorflow",
                           compute_precision=ct.precision.FLOAT32)

Results of testing the CoreML model:

from PIL import Image
img = Image.open('/Path/To/Desktop/dick3.png')
img = img.resize((480,480)) 
if img.mode != 'RGB':
    img = img.convert('RGB')
out_dict = mlmodel_from_tf.predict({"model_input_images": img})
print(out_dict) 
# {'Identity': array([[0.00386974, 0.9961302 ]], dtype=float32)}
# I believe the first element of the array represents the "confidence level that the content is NSFW." or I'm misunderstanding something?
@Steeeephen
Copy link
Contributor

Hey! - Sorry about the delay in getting round to this

Hmm tbh I've no experience in using CoreML models, so I'm quite limited in what I can do to help 😢

What results are you getting for that image with the normal SavedModel inference? It doesn't seem like you're recreating the preprocessing functions for images with that setup so I'm thinking that may be causing the issue

@ChouJay
Copy link
Author

ChouJay commented Dec 5, 2023

Hi @Steeeephen ,
The problem was indeed that I hadn't implemented the preprocess function.
After implementing the preprocess function in Swift, I was able to get the correct results.
Thank you very much for your guidance : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants