giovedì 9 gennaio 2020

Predizione classificazione immagini con Tensorflow da modelli .h5

In un esempio precedente avevo usato il modello .tflite per fare predizione di classificazione immagine.

Il modello e' stato creato da un train di Inception

============================================================

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

import sys

import tensorflow as tf

import tensorflow_hub as hub

from keras.models import load_model

model = tf.keras.models.load_model('incept.h5', custom_objects={'KerasLayer':hub.KerasLayer})
#print(model.get_config())
from keras.preprocessing import image
img = image.load_img(sys.argv[1])# , target_size=(299,299,3))
img  = image.img_to_array(img)
img  = img.reshape((1,) + img.shape)
img  = img/255
build_input_shape = img.reshape(-1,299,299,3)
#print (build_input_shape)
img_class=model.predict_classes(img) 
print (sys.argv[1])
print(img_class) 

Nessun commento:

Posta un commento

Nvidia Dev Env con Docker e Visual Code

Mi sono comprato un vecchio portatile MSI con una NVidia GeForce GTX 860M che supporta i driver 580.178.04 Cuda 13 La scheda video e' mo...