Skip to content

Instantly share code, notes, and snippets.

@FavioVazquez
Created May 2, 2018 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FavioVazquez/b1a43d8611e1fd2db9a3c61742156e97 to your computer and use it in GitHub Desktop.
Save FavioVazquez/b1a43d8611e1fd2db9a3c61742156e97 to your computer and use it in GitHub Desktop.
from keras.applications.inception_v3 import preprocess_input
from keras.preprocessing.image import img_to_array, load_img
import numpy as np
from pyspark.sql.types import StringType
from sparkdl import KerasImageFileTransformer
def loadAndPreprocessKerasInceptionV3(uri):
# this is a typical way to load and prep images in keras
image = img_to_array(load_img(uri, target_size=(299, 299))) # image dimensions for InceptionV3
image = np.expand_dims(image, axis=0)
return preprocess_input(image)
transformer = KerasImageFileTransformer(inputCol="uri", outputCol="predictions",
modelFile='model-full.h5', # local file path for model
imageLoader=loadAndPreprocessKerasInceptionV3,
outputMode="vector")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment