Giter Site home page Giter Site logo

ibm / max-image-caption-generator Goto Github PK

View Code? Open in Web Editor NEW
85.0 23.0 44.0 2.32 MB

IBM Code Model Asset Exchange: Show and Tell Image Caption Generator

Home Page: https://developer.ibm.com/exchanges/models/all/max-image-caption-generator/

License: Apache License 2.0

Python 96.77% Dockerfile 1.58% Starlark 1.66%
docker-image machine-learning machine-lerning-models coco-dataset

max-image-caption-generator's Introduction

Build Status Website Status

IBM Developer Model Asset Exchange: Image Caption Generator

This repository contains code to instantiate and deploy an image caption generation model. This model generates captions from a fixed vocabulary that describe the contents of images in the COCO Dataset. The model consists of an encoder model - a deep convolutional net using the Inception-v3 architecture trained on ImageNet-2012 data - and a decoder model - an LSTM network that is trained conditioned on the encoding from the image encoder model. The input to the model is an image, and the output is a sentence describing the image content.

The model is based on the Show and Tell Image Caption Generator Model. The checkpoint files are hosted on IBM Cloud Object Storage. The code in this repository deploys the model as a web service in a Docker container. This repository was developed as part of the IBM Code Model Asset Exchange.

Model Metadata

Domain Application Industry Framework Training Data Input Data Format
Vision Image Caption Generator General TensorFlow COCO Images

References

Licenses

Component License Link
This repository Apache 2.0 LICENSE
Model Weights MIT Pretrained Show and Tell Model
Model Code (3rd party) Apache 2.0 im2txt
Test assets Various Sample README

Pre-requisites:

  • docker: The Docker command-line interface. Follow the installation instructions for your system.
  • The minimum recommended resources for this model is 2GB Memory and 2 CPUs.
  • If you are on x86-64/AMD64, your CPU must support AVX at the minimum.

Deployment options

Deploy from Quay

To run the docker image, which automatically starts the model serving API, run:

$ docker run -it -p 5000:5000 quay.io/codait/max-image-caption-generator

This will pull a pre-built image from the Quay.io container registry (or use an existing image if already cached locally) and run it. If you'd rather checkout and build the model locally you can follow the run locally steps below.

Deploy on Red Hat OpenShift

You can deploy the model-serving microservice on Red Hat OpenShift by following the instructions for the OpenShift web console or the OpenShift Container Platform CLI in this tutorial, specifying quay.io/codait/max-image-caption-generator as the image name.

Deploy on Kubernetes

You can also deploy the model on Kubernetes using the latest docker image on Quay.

On your Kubernetes cluster, run the following commands:

$ kubectl apply -f https://raw.githubusercontent.com/IBM/MAX-Image-Caption-Generator/master/max-image-caption-generator.yaml

The model will be available internally at port 5000, but can also be accessed externally through the NodePort.

A more elaborate tutorial on how to deploy this MAX model to production on IBM Cloud can be found here.

Run Locally

  1. Build the Model
  2. Deploy the Model
  3. Use the Model
  4. Development
  5. Cleanup

1. Build the Model

Clone this repository locally. In a terminal, run the following command:

$ git clone https://github.com/IBM/MAX-Image-Caption-Generator.git

Change directory into the repository base folder:

$ cd MAX-Image-Caption-Generator

To build the docker image locally, run:

$ docker build -t max-image-caption-generator .

All required model assets will be downloaded during the build process. Note that currently this docker image is CPU only (we will add support for GPU images later).

2. Deploy the Model

To run the docker image, which automatically starts the model serving API, run:

$ docker run -it -p 5000:5000 max-image-caption-generator

3. Use the Model

The API server automatically generates an interactive Swagger documentation page. Go to http://localhost:5000 to load it. From there you can explore the API and also create test requests.

Use the model/predict endpoint to load a test file and get captions for the image from the API.

pic

You can also test it on the command line, for example:

$ curl -F "image=@samples/surfing.jpg" -X POST http://localhost:5000/model/predict
{
  "status": "ok",
  "predictions": [
    {
      "index": "0",
      "caption": "a man riding a wave on top of a surfboard .",
      "probability": 0.038827644239537
    },
    {
      "index": "1",
      "caption": "a person riding a surf board on a wave",
      "probability": 0.017933410519265
    },
    {
      "index": "2",
      "caption": "a man riding a wave on a surfboard in the ocean .",
      "probability": 0.0056628732021868
    }
  ]
}

4. Development

To run the Flask API app in debug mode, edit config.py to set DEBUG = True under the application settings. You will then need to rebuild the docker image (see step 1).

5. Cleanup

To stop the Docker container, type CTRL + C in your terminal.

Links

Resources and Contributions

If you are interested in contributing to the Model Asset Exchange project or have any queries, please follow the instructions here.

max-image-caption-generator's People

Contributors

ajbozarth avatar animeshsingh avatar bdwyer2 avatar dependabot[bot] avatar djalova avatar frreiss avatar lresende avatar mlnick avatar ptitzler avatar xuhdev avatar xwu0226 avatar yil532 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

max-image-caption-generator's Issues

Deploy on Amazon SageMaker

Do you have any recommendations on deploying this to Amazon SageMaker?

Likewise, can I retrain on my custom dataset?

Thanks in advance

inconsistent link to COS directory for model files

the README contains this link to the model files:

this works. however, it is different than the link in the Dockerfile:

i would expect both of these to point to the same set of model files.
in addition, both of the links should be pointing to the new US cross region:

s3.us.cloud-object-storage.appdomain.cloud

because the old one has been deprecated:

s3-api.us-geo.objectstorage.softlayer.net

fix or disable downstream build

The downstream build (max-image-caption-Generator
-web-app) has been failing for a while. We should either fix this or disable this.

Unable to resolve host address

Hello! I was trying to deploy the model locally, so after cloning the github repository, I had to build the docker file with the command : sudo docker build -t max-image-caption-generator .
However, at Step 4/10 I get the error:
unable_host

Not working from docker hub

The image doesn't work when pulled from Docker Hub. Tried on 2 separate Ubuntu machine and got the same result

Unable to find image 'codait/max-image-caption-generator-web-app:latest' locally
latest: Pulling from codait/max-image-caption-generator-web-app
ff3a5c916c92: Already exists 
44014a6ad6bc: Pull complete 
2f8f143a8987: Pull complete 
02b100ec4a6d: Pull complete 
c74d77b2e916: Pull complete 
d5ebd2bdbe85: Pull complete 
9bd06c12144a: Pull complete 
Digest: sha256:aefaf3a41e1f9b51c4fbf39791bdd8303ef6084d7e8e4e0db0090b57a46a8243
Status: Downloaded newer image for codait/max-image-caption-generator-web-app:latest
INFO: Connecting to ML endpoint at http://localhost:5000/model/predict
ERROR: Cannot connect to the Image Caption Generator REST endpoint at http://localhost:5000

Add mime type inference when uploaded images are missing mime type

#9 added error checking for file type, but did so using mime type. This means that uploads with missing mime type (mime type = None) will fail even if the image is valid. This was discovered and addressed by the web app in IBM/MAX-Image-Caption-Generator-Web-App#39

As per discussion in #9 we should look into adding the mime type fix in the model as well. This can either be done using the same method as the web app or by using the more robust python magic library.

NumberFormatException - $.predictions[0].probability

Hi,

I am trying to call the Image Caption Generator from Android app via RetroFit2.

When i try to test the API with the default image available in the Emulator I am getting the following exception.

My Guess is that this issue is from the API, Please correct me if I am wrong.

com.google.gson.JsonSyntaxException: java.lang.NumberFormatException: Expected an int but was 9.84082025545015e-05 at line 1 column 140 path $.predictions[0].probability
com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:245)
com.google.gson.internal.bind.TypeAdapters$7.read(TypeAdapters.java:235)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
retrofit2.ServiceMethod.toResponse(ServiceMethod.java:119)
retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:218)
retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:112)
okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
java.lang.Thread.run(Thread.java:764)

Training on custom dataset ?

Hey, I am curious if I could use my own dataset for training instead of the COCO dataset which is already being used.

/model/predict doesn't handle invalid input

If an invalid input (such as a text file or certain images) is provided as payload the server returns status code 500 (Internal Server Error). The log output contains stack trace information, indicating that the input is not valid.

To recreate:

  • Invoke the /model/predict endpoint and provide an invalid "image" as input

Actual result:

  • Server returns HTTP status code 500 (Internal Server Error)

Expected result:

  • Server returns HTTP status code 400 (Bad Request)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.