Skip to content

Instantly share code, notes, and snippets.

@starkfire
Last active October 13, 2022 14:39
Show Gist options
  • Save starkfire/eaff52bcd25d0a5351d22bd9e016b227 to your computer and use it in GitHub Desktop.
Save starkfire/eaff52bcd25d0a5351d22bd9e016b227 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import os, json
from glob import glob
import tensorflow.keras
import tensorflow as tf
from tensorflow.keras.applications import inception_v3, vgg16
from tensorflow.keras.preprocessing import image
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
from tensorflow.keras import backend as K
from tensorflow.keras.applications.imagenet_utils import preprocess_input, decode_predictions
import numpy as np
from IPython.display import Image
model = inception_v3.InceptionV3(weights='imagenet', include_top=True)
image_path = './test/'
model.summary()
len(model.layers)
img_path = os.path.join(image_path, 'image_here.jpg') # change dis
img = image.load_img(img_path, target_size=(299,299))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = inception_v3.preprocess_input(x)
print('Input Image Shape: ', x.shape)
preds = model.predict(x)
print('Predicted: ', decode_predictions(preds))
Image(img_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment