Last active
July 18, 2019 08:10
-
-
Save imyoungyang/e688cf2a7be44b7247716cc522dcf645 to your computer and use it in GitHub Desktop.
sample code
This file contains hidden or 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
# Bird | |
!wget -O /tmp/test.jpg https://upload.wikimedia.org/wikipedia/commons/1/17/Rotkehlchen_bird.jpg | |
file_name = '/tmp/test.jpg' | |
from IPython.display import Image | |
Image(file_name) | |
# resize and padding | |
from matplotlib.pyplot import imshow | |
from PIL import Image | |
import numpy as np | |
%matplotlib inline | |
desired_size = 32 | |
im = Image.open(file_name) | |
old_size = im.size | |
ratio = float(desired_size)/max(old_size) | |
new_size = tuple([int(x*ratio) for x in old_size]) | |
new_size | |
im = im.resize(new_size, Image.ANTIALIAS) | |
np_im = np.array(im) | |
np_im.shape | |
new_im = Image.new("RGB", (desired_size, desired_size)) | |
new_im.paste(im, ((desired_size-new_size[0])//2, | |
(desired_size-new_size[1])//2)) | |
np_new_im = np.array(new_im) | |
np_new_im.shape | |
imshow(np_new_im) | |
# reshape | |
np_new_im = np_new_im[np.newaxis, ...] | |
np_new_im.shape | |
# response | |
response = predictor.predict({'inputs_input': np_new_im}) | |
response | |
# use other people's predictor | |
import json | |
from sagemaker.tensorflow import TensorFlowPredictor | |
predictor = TensorFlowPredictor('sagemaker-tensorflow-2019-07-17-03-09-42-707') | |
result = predictor.predict({'inputs_input': np_new_im}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment