I am trying to alter my inception network (coded in keras) to take base64 image strings as input for predictions. After that I want to save it as a tensorflow (.pb - file) network since that's what Google ml engine requires.
Normal way of predicting is as this :
img = "image.jpg"
image = image.load_img(img)
x = image.img_to_array(image)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
score = model.predict(x)
So I'm trying to implement this and then save it like this:
input_images = tf.placeholder(dtype=tf.string, shape=[])
decoded = tf.image.decode_image(input_images, channels=3)
image = tf.cast(decoded, dtype=tf.uint8)
afbeelding = Image.open(io.BytesIO(image))
x = image.img_to_array(afbeelding)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
scores = model.predict(decoded)
signature = predict_signature_def(inputs={'image_bytes': input_images},
outputs={'predictions': scores})
with K.get_session() as sess:
builder.add_meta_graph_and_variables(sess=sess,
tags=[tag_constants.SERVING],
signature_def_map={
signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: signature})
builder.save()
But image as a tensor, not an actual image. To be honest I don't know how to fully implement it. There's no way of getting the actual value of a tensor right? Really hope someone can help me with this.