我正在使用Keras预测图像类.它适用于Google Cloud ML(GCML),但为了提高效率,需要将其更改为传递base64字符串而不是json数组. 相关文档
我可以轻松运行python代码将base64字符串解码为json数组,但是当使用GCML时,我没有机会运行预处理步骤(除非在Keras中使用Lambda层,但我认为不是正确的方法).
另一个答案建议添加tf.placeholder类型tf.string,这是有道理的,但如何将其纳入Keras模型?
以下是培训模型和保存GCML导出模型的完整代码...
import os
import numpy as np
import tensorflow as tf
import keras
from keras import backend as K
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras.preprocessing import image
from tensorflow.python.platform import gfile
IMAGE_HEIGHT = 138
IMAGE_WIDTH = 106
NUM_CLASSES = 329
def preprocess(filename):
# decode the image file starting from the filename
# end up with pixel values that …Run Code Online (Sandbox Code Playgroud) 我正在研究Google Cloud ML,我希望能够预测jpeg图像.为此,我想使用:
gcloud beta ml预测--instances = INSTANCES --model = MODEL [--version = VERSION]
(https://cloud.google.com/ml/reference/commandline/predict)
Instances是json文件的路径,其中包含有关image的所有信息.如何从jpeg图像创建json文件?
非常感谢!!