forked from taoxugit/AttnGAN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:sethjuarez/AttnGAN
- Loading branch information
Showing
7 changed files
with
206 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
docker build -t "attngan" . | ||
docker build -t "attngan" -f dockerfile.cpu . | ||
REM docker run -it -e BLOB_KEY=KEY -p 5678:8080 attngan | ||
REM curl -H "Content-Type: application/json" -X POST -d '{"caption":"the bird has a yellow crown and a black eyering that is round"}' https://attgan.azurewebsites.net/api/v1.0/bird |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM nvidia/cuda | ||
|
||
RUN apt-get update \ | ||
&& apt-get upgrade -y \ | ||
&& apt-get install -y \ | ||
python-pip \ | ||
python2.7 \ | ||
&& apt-get autoremove \ | ||
&& apt-get clean | ||
|
||
RUN mkdir -p /usr/src/app | ||
WORKDIR /usr/src/app | ||
|
||
COPY requirements.txt /usr/src/app/ | ||
RUN pip install --upgrade pip | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
RUN pip install http://download.pytorch.org/whl/cu90/torch-0.3.1-cp27-cp27mu-linux_x86_64.whl | ||
RUN pip install torchvision | ||
|
||
COPY . /usr/src/app | ||
|
||
ENV NVIDIA_VISIBLE_DEVICES all | ||
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility | ||
ENV GPU True | ||
ENV EXPORT_MODEL False | ||
|
||
EXPOSE 8080 | ||
|
||
CMD ["python", "main.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,93 @@ | ||
#!flask/bin/python | ||
import os | ||
import time | ||
import random | ||
from eval import * | ||
from flask import Flask, jsonify, request, abort | ||
from applicationinsights import TelemetryClient | ||
from applicationinsights.requests import WSGIApplication | ||
from applicationinsights.exceptions import enable | ||
from miscc.config import cfg | ||
from werkzeug.contrib.profiler import ProfilerMiddleware | ||
#from werkzeug.contrib.profiler import ProfilerMiddleware | ||
|
||
enable(os.environ["TELEMETRY"]) | ||
app = Flask(__name__) | ||
|
||
|
||
# load word dictionaries | ||
wordtoix, ixtoword = word_index() | ||
# lead models | ||
text_encoder, netG = models(len(wordtoix)) | ||
# load blob service | ||
blob_service = BlockBlobService(account_name='attgan', account_key=os.environ["BLOB_KEY"]) | ||
app.wsgi_app = WSGIApplication(os.environ["TELEMETRY"], app.wsgi_app) | ||
|
||
@app.route('/api/v1.0/bird', methods=['POST']) | ||
def create_bird(): | ||
if not request.json or not 'caption' in request.json: | ||
abort(400) | ||
|
||
response = eval(request.json['caption']) | ||
caption = request.json['caption'] | ||
|
||
t0 = time.time() | ||
urls = generate(caption, wordtoix, ixtoword, text_encoder, netG, blob_service) | ||
t1 = time.time() | ||
|
||
response = { | ||
'small': urls[0], | ||
'medium': urls[1], | ||
'large': urls[2], | ||
'map1': urls[3], | ||
'map2': urls[4], | ||
'caption': caption, | ||
'elapsed': t1 - t0 | ||
} | ||
return jsonify({'bird': response}), 201 | ||
|
||
@app.route('/api/v1.0/birds', methods=['POST']) | ||
def create_birds(): | ||
if not request.json or not 'caption' in request.json: | ||
abort(400) | ||
|
||
caption = request.json['caption'] | ||
|
||
t0 = time.time() | ||
urls = generate(caption, wordtoix, ixtoword, text_encoder, netG, blob_service, copies=6) | ||
t1 = time.time() | ||
|
||
response = { | ||
'bird1' : { 'small': urls[0], 'medium': urls[1], 'large': urls[2] }, | ||
'bird2' : { 'small': urls[3], 'medium': urls[4], 'large': urls[5] }, | ||
'bird3' : { 'small': urls[6], 'medium': urls[7], 'large': urls[8] }, | ||
'bird4' : { 'small': urls[9], 'medium': urls[10], 'large': urls[11] }, | ||
'bird5' : { 'small': urls[12], 'medium': urls[13], 'large': urls[14] }, | ||
'bird6' : { 'small': urls[15], 'medium': urls[16], 'large': urls[17] }, | ||
'caption': caption, | ||
'elapsed': t1 - t0 | ||
} | ||
return jsonify({'bird': response}), 201 | ||
|
||
@app.route('/', methods=['GET']) | ||
def get_bird(): | ||
return 'hello!' | ||
return 'Version 1' | ||
|
||
if __name__ == '__main__': | ||
app.config['PROFILE'] = True | ||
app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) | ||
app.run(host='0.0.0.0', port=8080, debug=True) | ||
t0 = time.time() | ||
tc = TelemetryClient(os.environ["TELEMETRY"]) | ||
|
||
# gpu based | ||
cfg.CUDA = os.environ["GPU"].lower() == 'true' | ||
tc.track_event('container initializing', {"CUDA": str(cfg.CUDA)}) | ||
|
||
# load word dictionaries | ||
wordtoix, ixtoword = word_index() | ||
# lead models | ||
text_encoder, netG = models(len(wordtoix)) | ||
# load blob service | ||
blob_service = BlockBlobService(account_name='attgan', account_key=os.environ["BLOB_KEY"]) | ||
|
||
seed = 100 | ||
random.seed(seed) | ||
np.random.seed(seed) | ||
torch.manual_seed(seed) | ||
if cfg.CUDA: | ||
torch.cuda.manual_seed_all(seed) | ||
|
||
#app.config['PROFILE'] = True | ||
#app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) | ||
#app.run(host='0.0.0.0', port=8080, debug = True) | ||
|
||
t1 = time.time() | ||
tc.track_event('container start', {"starttime": str(t1-t0)}) | ||
app.run(host='0.0.0.0', port=8080) |
Oops, something went wrong.