|
import tensorflow as tf |
|
from keras_tuner import HyperParameters |
|
from src.models import MakeHyperModel |
|
from src.preprocessing import get_data_augmentation |
|
from src.config import IMAGE_SIZE |
|
|
|
data_augmentation = get_data_augmentation() |
|
|
|
img = tf.keras.preprocessing.image.load_img( |
|
"examples/cat2.jpg", target_size=IMAGE_SIZE |
|
) |
|
img_array = tf.keras.preprocessing.image.img_to_array(img) |
|
img_array = tf.expand_dims(img_array, 0) |
|
|
|
latest = tf.train.latest_checkpoint('./tuner_model/cat-vs-dog/trial_0484d8d758a5ef7b91ca97d334ba7870/checkpoints/epoch_0') |
|
hypermodel = MakeHyperModel(input_shape=IMAGE_SIZE + (3,), num_classes=2, data_augmentation=data_augmentation) |
|
model = hypermodel.build(hp=HyperParameters()) |
|
model.load_weights(latest).expect_partial() |
|
|
|
|
|
predictions = model.predict(img_array) |
|
score = predictions[0] |
|
print( |
|
"This image is %.2f percent cat and %.2f percent dog." |
|
% (100 * (1 - score), 100 * score) |
|
) |
|
|