# 下面是使用tensorflow实现图像分类的预测代码(部分)
# create model
feature = resnet50(num_classes=num_classes, include_top=False)
feature.trainable = False
model = tf.keras.Sequential([feature,
tf.keras.layers.GlobalAvgPool2D(),
tf.keras.layers.Dropout(rate=0.5),
tf.keras.layers.Dense(1024, activation="relu"),
tf.keras.layers.Dropout(rate=0.5),
tf.keras.layers.Dense(num_classes),
tf.keras.layers.Softmax()])
# load weights
weights_path = './save_weights/resNet_50.ckpt'
assert len(glob.glob(weights_path+"*")), "cannot find {}".format(weights_path)
model.load_weights(weights_path)
# prediction
result = np.squeeze(model.predict(img))