diff options
author | Evan Shelhamer <shelhamer@imaginarynumber.net> | 2015-03-06 19:36:29 -0800 |
---|---|---|
committer | Evan Shelhamer <shelhamer@imaginarynumber.net> | 2015-03-08 00:16:27 -0800 |
commit | 5c84795572cf08f020dab31af43e7d8478628f44 (patch) | |
tree | ad9a7229b3ab68eb2952293faa216d74cfefc729 /examples | |
parent | 0b398925d94df4445a6cf28c30cdf2802260903a (diff) | |
download | caffeonacl-5c84795572cf08f020dab31af43e7d8478628f44.tar.gz caffeonacl-5c84795572cf08f020dab31af43e7d8478628f44.tar.bz2 caffeonacl-5c84795572cf08f020dab31af43e7d8478628f44.zip |
[pycaffe] align web demo with #1728 and #1902
Diffstat (limited to 'examples')
-rw-r--r-- | examples/web_demo/app.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/examples/web_demo/app.py b/examples/web_demo/app.py index e456526f..208b1da0 100644 --- a/examples/web_demo/app.py +++ b/examples/web_demo/app.py @@ -10,12 +10,13 @@ import tornado.wsgi import tornado.httpserver import numpy as np import pandas as pd -from PIL import Image as PILImage +import Image import cStringIO as StringIO import urllib -import caffe import exifutil +import caffe + REPO_DIRNAME = os.path.abspath(os.path.dirname(__file__) + '/../..') UPLOAD_FOLDER = '/tmp/caffe_demos_uploads' ALLOWED_IMAGE_EXTENSIONS = set(['png', 'bmp', 'jpg', 'jpe', 'jpeg', 'gif']) @@ -80,7 +81,7 @@ def classify_upload(): def embed_image_html(image): """Creates an image embedded in HTML base64 format.""" - image_pil = PILImage.fromarray((255 * image).astype('uint8')) + image_pil = Image.fromarray((255 * image).astype('uint8')) image_pil = image_pil.resize((256, 256)) string_buf = StringIO.StringIO() image_pil.save(string_buf, format='png') @@ -114,15 +115,18 @@ class ImagenetClassifier(object): "File for {} is missing. Should be at: {}".format(key, val)) default_args['image_dim'] = 256 default_args['raw_scale'] = 255. - default_args['gpu_mode'] = False def __init__(self, model_def_file, pretrained_model_file, mean_file, raw_scale, class_labels_file, bet_file, image_dim, gpu_mode): logging.info('Loading net and associated files...') + if gpu_mode: + caffe.set_mode_gpu() + else: + caffe.set_mode_cpu() self.net = caffe.Classifier( model_def_file, pretrained_model_file, image_dims=(image_dim, image_dim), raw_scale=raw_scale, - mean=np.load(mean_file), channel_swap=(2, 1, 0), gpu=gpu_mode + mean=np.load(mean_file).mean(1).mean(1), channel_swap=(2, 1, 0) ) with open(class_labels_file) as f: |