

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import numpy as np import tensorflow as tf from tensorflow import keras # Load pretrained model model = tf.keras.applications.MobileNetV2(include_top=True, weights='imagenet') # Load and preprocess image img = keras.preprocessing.image.load_img('/content/panda.jpeg', target_size=(224, 224)) x = keras.preprocessing.image.img_to_array(img) x = np.expand_dims(x, axis=0) # Preprocess input for MobileNetV2 x = tf.keras.applications.mobilenet_v2.preprocess_input(x) # Make predictions preds = model.predict(x) # Decode predictions decoded_preds = keras.applications.mobilenet_v2.decode_predictions(preds, top=1)[0] print(decoded_preds) |