Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
gsganden committed Aug 22, 2019
2 parents 8c52be7 + e826d05 commit 0fa55aa
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Expand Up @@ -10,4 +10,5 @@ Pull Request Checklist
Maintainer's responsibilities:
- [ ] `_version.py` has been updated.
- [ ] `CHANGELOG.md` has been updated.
- [ ] Updated app container has been pushed, if relevant.
- [ ] Updated app container has been pushed, if relevant, with current version number.
- [ ] App container version number has been updated in README.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Expand Up @@ -3,10 +3,17 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

# [1.2.2] - 2019-8-22
# [1.2.3] - 2019-8-22
### Changed
- Tests and instructions now refer to "localhost" instead of "0.0.0.0".

# [1.2.2] - 2019-8-19
### Fixed
- App can actually accept image files with capitalized extensions (e.g. ".JPG"").
### Added
- Explicit version numbers on dockerhub containers.


# [1.2.1] - 2019-8-3
### Fixed
- App can accept image files with capitalized extensions (e.g. ".JPG").
Expand Down
25 changes: 21 additions & 4 deletions README.md
Expand Up @@ -16,9 +16,24 @@ This project uses deep learning computer vision to label images taken by motion-
If you just want to get labels for your images, you can use the following steps to run a service that passes images through a trained model.

1. Make sure [Docker](https://www.docker.com/get-started) is installed and running.
2. Run `docker pull gsganden/autofocus_serve` to download the app image. (Note that it takes up about 4GB of disk space.)
3. Run `docker run -p 8000:8000 gsganden/autofocus_serve` to start the app.
4. Make POST requests against the app to get predictions. For instance, with the base of this repo as the working directory you can send the image `fawn.jpeg` to the app with `curl -F "file=@./gallery/fawn.jpeg" -X POST http://localhost:8000/predict`. Or you can create a zip file of the `gallery` directory and send it to the app with `curl -F "file=@gallery.zip" -X POST http://localhost:8000/predict_zip`. See `autofocus/predict/example_post.py` or `autofocus/predict/example_post.R` for example scripts that make requests using Python and R, respectively.
2. Run `docker pull gsganden/autofocus_serve:1.2.2` to download the app image. (Note that it takes up about 4GB of disk space.)
3. Run `docker run -p 8000:8000 gsganden/autofocus_serve:1.2.2` to start the app.
4. Make POST requests against the app to get predictions.

For instance, with the base of this repo as the working directory you can send the image `fawn.JPG` to the app with this command:

```bash
curl -F "file=@./gallery/fawn.JPG" -X POST http://localhost:8000/predict
```

Or send the zipped `gallery` directory to the app with this command:

```bash
curl -F "file=@gallery.zip" -X POST http://localhost:8000/predict_zip
```

See `autofocus/predict/example_post.py` and `autofocus/predict/example_post.R` for example scripts that make requests using Python and R, respectively.
>>>>>>> master
For a single image, the app will respond with a JSON object that indicates the model's probability that the image contains an animal in each of the categories that it has been trained on. For instance, it might give the following response for an image containing raccoons:

Expand Down Expand Up @@ -48,6 +63,8 @@ For a single image, the app will respond with a JSON object that indicates the m
}
```

The model generates each of these probabilities separately to allow for the possibility e.g. that an image contains both a human and a dog, so they will not sum to 1 in general.

The `/predict_zip` endpoint returns a JSON object mapping file paths to model probabilities formatted as above.

During development, it is convenient to run the app in debug mode with the local directory mounted to the Docker container so that changes you make locally are reflected in the service immediately:
Expand Down Expand Up @@ -116,6 +133,6 @@ To test the app, run `pip install -r requirements-dev.txt` and then `pytest`. Th

![buck](./gallery/buck.jpeg)

![fawn](./gallery/fawn.jpeg)
![fawn](./gallery/fawn.JPG)

![racoons](gallery/raccoons.jpeg)
4 changes: 2 additions & 2 deletions autofocus/predict/app/app.py
Expand Up @@ -5,8 +5,8 @@
from flask import Flask, jsonify, make_response, request
from werkzeug import secure_filename

from model import predict_multiple, predict_single
from utils import allowed_file, filter_image_files, list_zip_files
from .model import predict_multiple, predict_single
from .utils import allowed_file, filter_image_files, list_zip_files

# We are going to upload the files to the server as part of the request, so set tmp folder here.
UPLOAD_FOLDER = "/tmp/"
Expand Down
Binary file modified gallery.zip
Binary file not shown.
File renamed without changes
6 changes: 3 additions & 3 deletions tests/test_app.py
Expand Up @@ -6,11 +6,11 @@


def test_sample_predict_request():
filepath = Path(__file__).resolve().parents[1] / "gallery" / "fawn.jpeg"
filepath = Path(__file__).resolve().parents[1] / "gallery" / "raccoons.jpeg"
response = requests.post(
f"{BASE_URL}/predict", files={"file": open(filepath, "rb")}
)
assert response.json()["deer"] > 0.9
assert response.json()["raccoon"] > 0.9


def test_sample_predict_request_JPG():
Expand All @@ -26,4 +26,4 @@ def test_sample_predict_zip_request():
response = requests.post(
f"{BASE_URL}/predict_zip", files={"file": open(filepath, "rb")}
)
assert len(response.json()) == 5
assert len(response.json()) == 4

0 comments on commit 0fa55aa

Please sign in to comment.