Google Vision API Image detection 101

We’re handling 200,000 images from customers so far, keeping the peace can be tough. User uploaded content is always questionable, and being a closed network I’d like to keep irritated customers to a minimum. Google Vision API allows you to filter out the bad images systematically. I’m just getting started working with the Vision API, and it turns out Google is Alpha’ing AutoML, which is a smarted version you can train your own models on! I can’t wait to give it a try and review it later.

GOOGLE – IF YOU CAN HEAR ME… PLEASE HOOK ME UP WITH AUTOML!!! 😛

1.) create a service account on google cloud platform by heading to
left menu : IAM & Admin : Service accounts

2.) obtain your key in JSON format from Google, don’t lose it or you’ll need to delete and recreate a new one.

3.) Save the JSON key as key.json and install python samples. Then lets test the API.

python3 -m pip install google.cloud  
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git  
cd python-docs-samples  
mkdir python-docs-samples/keys  
cp json.key python-docs-samples/keys  
export GOOGLE_APPLICATION_CREDENTIALS='python-docs-samples/keys/json.key'  
python3 detect.py safe-search-uri $url

Safe search:  
adult: VERY_UNLIKELY  
medical: VERY_UNLIKELY  
spoofed: VERY_UNLIKELY  
violence: VERY_UNLIKELY  
racy: VERY_UNLIKELY

More than likely, if you are using a http:// , https:// , or gs:// hosted file, you will want to use the *-uri option. From what I can tell the non-uri options are used for locally stored filesystem images.

Instead of using safe-search-uri you have more options to choose from to select metadata.

faces               Detect faces in an image.

faces-uri           Detect faces in the file located in Google Cloud
                    Storage or the web.

labels              Detect labels in the file.

labels-uri          Detects labels in the file located in Google Cloud
                    Storage or on the Web.

landmarks           Detect landmarks in the file.

landmarks-uri       Detect landmarks in the file located in Google Cloud
                    Storage or on the Web.

text                Detect text in the file.

text-uri            Detect text in the file located in Google Cloud
                    Storage or on the Web.

logos               Detect logos in the file.

logos-uri           Detect logos in the file located in Google Cloud
                    Storage or on the Web.

safe-search         Detect unsafe features in the file.

safe-search-uri     Detects unsafe features in the file located in Google
                    Cloud Storage or on the Web.

properties          Detect image properties in the file.

properties-uri      Detects image properties in the file located in Google
                    Cloud Storage or on the Web.

web                 Detects web annotations given an image.

web-uri             Detects web annotations in the file located in Google
                    Cloud Storage.

web-geo             Detects web annotations given an image, using the
                    geotag metadata in the image to detect web entities.

web-geo-uri         Detects web annotations given an image in the file
                    located in Google Cloud Storage., using the geotag
                    metadata in the image to detect web entities.

crophints           Detects crop hints in an image.

crophints-uri       Detects crop hints in the file located in Google Cloud
                    Storage.

document            Detects document features in an image.

document-uri        Detects document features in the file located in
                    Google Cloud Storage.

So far so good, feel free to leave a comment with anything you’d like me to add.

Leave a Reply

Your email address will not be published. Required fields are marked *