低调小萱

导航

 
 
from tensorflow.keras.applications.mobilenet import MobileNet
from tensorflow.keras.preprocessing import image
from keras.models import Model
from tensorflow.keras.applications.mobilenet import preprocess_input
import numpy as np
import cv2 as cv

# include_top 为真:要分类层   为假:不要分类层
# model = MobileNet(weights='imagenet', include_top=True)
base_model = MobileNet(weights='imagenet')
model = Model(inputs=base_model.input, outputs=base_model.get_layer('dropout').output)

img_path = 'sample1/1.png'
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)

features = model.predict(x)
print(features.shape)  
posted on 2021-07-16 14:34  低调小萱  阅读(362)  评论(0)    收藏  举报