Skip to content

Instantly share code, notes, and snippets.

@cia-rana
Last active October 11, 2019 10:37
Show Gist options
  • Save cia-rana/9337ac6c0fe48680c4edd7c7782f0a78 to your computer and use it in GitHub Desktop.
Save cia-rana/9337ac6c0fe48680c4edd7c7782f0a78 to your computer and use it in GitHub Desktop.
Xception Check
FROM tensorflow/tensorflow:latest-py3
RUN pip install pillow
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}")
build:
docker build -t tensorflow-pil .
run:
docker run -it --rm -v $(pwd):/workdir -w /workdir tensorflow-pil python main.py ${IMAGE_PATH}
@cia-rana
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment