Code: Select all
inceptionv3_model = InceptionV3(weights="imagenet", include_top=False, input_shape=(224, 224, 3))
inceptionv3_model.trainable = False
model = Sequential()
model.add(inceptionv3_model)
model.add(Conv2D(32, (3, 3), activation='relu', padding='same'))
model.add(GlobalAveragePooling2D())
# flatten
model.add(Flatten())
# hidden layer
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.2))
# output layer
model.add(Dense(3, activation='softmax'))
Code: Select all
saved_model_path = '/kaggle/working/models/cdb_model/1'
tf.saved_model.save(model, saved_model_path)
Code: Select all
docker pull tf/serving
docker run -it -v models:/models -p 8501:8501 --entrypoint /bin/ba
sh tensorflow/serving
tensorflow_model_server --rest_api_port=8501 --model_name=cdb_model --model_base_path=
/models/cdb_model/
Aber wenn post < /code> Bild für die Vorhersage < /p>
postet
Code: Select all
def images_preprocessing(filename):
img = image.load_img(filename, target_size=(224, 224))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = img_array / 255.0
return img_array
image = images_preprocessing(cat_path)
json_data = {
"instances": image.tolist()
}
endpoint = "http://localhost:8501/v1/models/cdb_model:predict"
response = requests.post(endpoint, json=json_data)
predictions = response.json()
print(predictions)
< /code>
JSON Rückgabefehler: < /p>
{'error': 'Could not find variable batch_normalization_7/beta. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Resource localhost/batch_normalization_7/beta/N10tensorflow3VarE does not exist.\n\t [[{{function_node __inference_serving_default_199623}}{{node sequential_1/inception_v3_1/batch_normalization_7_1/Cast_2/ReadVariableOp}}]]'}