Last active
October 11, 2019 10:37
-
-
Save cia-rana/9337ac6c0fe48680c4edd7c7782f0a78 to your computer and use it in GitHub Desktop.
Xception Check
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
FROM tensorflow/tensorflow:latest-py3 | |
RUN pip install pillow |
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
import sys | |
import numpy as np | |
from PIL import Image | |
from tensorflow.python.keras.applications.xception import Xception, preprocess_input | |
from tensorflow.python.keras.models import Model | |
image = Image.open(sys.argv[1]).convert('RGB') | |
l = np.asarray(image.resize((299,299))).tolist() | |
base_model = Xception(include_top=True, weights='imagenet') | |
xception = Model(inputs=base_model.inputs, outputs=base_model.output) | |
raw_image = preprocess_input(np.expand_dims(l, axis=0)) | |
vec = np.squeeze(xception.predict(raw_image)).tolist() | |
print("index, value") | |
for i, e in enumerate(vec): | |
if e > 0.001953125: | |
print(f"{i}, {e}") |
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
build: | |
docker build -t tensorflow-pil . | |
run: | |
docker run -it --rm -v $(pwd):/workdir -w /workdir tensorflow-pil python main.py ${IMAGE_PATH} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref for index: https://gist.github.com/xkumiyu/dd200f3f51986888c9151df4f2a9ef30