import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing import image

# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
import cv2
import os
import glob


print(tf.__version__)

model = tf.keras.models.load_model(
    '../model/my_model.h5',
    custom_objects=None,
    compile=True,
    options=None)

train_datagen = ImageDataGenerator(
    rotation_range=20,
    width_shift_range=0.2,
    height_shift_range=0.2,
    horizontal_flip=True,
    vertical_flip=True,
    preprocessing_function=preprocess_input,
    validation_split=0.2
)

img_size = (150, 150)

training_set = train_datagen.flow_from_directory(
    '../dataset',
    target_size=img_size,
    class_mode='binary',
    subset='training'
)

testing_set = train_datagen.flow_from_directory(
    '../dataset',
    target_size=img_size,
    class_mode='binary',
    subset='validation'
)

loss, acc = model.evaluate(training_set)

img_dir = "../dataset/pred/"
data_path = os.path.join(img_dir, '*.jpg')
files = glob.glob(data_path)
data = []
results = []

for file in files:
    test_images = image.load_img(file, target_size=img_size)
    test_images = image.img_to_array(test_images)
    test_images = np.expand_dims(test_images, axis=0)
    images = np.vstack([test_images])
    classes = model.predict(images, batch_size=10)
    classes = np.round(classes)
    data.append(file)
    results.append(classes)

for x, y in zip(data, results):
    print(x, y)

W = 4
L = 4
fig, axes = plt.subplots(L, W, figsize=(12, 12))
axes = axes.ravel()
for i in np.arange(0, L * W):
    img = cv2.imread(data[i])
    axes[i].imshow(img)
    axes[i].set_title(results[i])
    axes[i].set_xticks([])
    axes[i].set_yticks([])

fig.tight_layout()
fig.savefig('image.png', bbox_inches='tight')

a4dee2eb34b3a83311fa3d87ee90fb91c2cc23c3
<mask token>

<mask token>
print(tf.__version__)
<mask token>
for file in files:
    test_images = image.load_img(file, target_size=img_size)
    test_images = image.img_to_array(test_images)
    test_images = np.expand_dims(test_images, axis=0)
    images = np.vstack([test_images])
    classes = model.predict(images, batch_size=10)
    classes = np.round(classes)
    data.append(file)
    results.append(classes)
for x, y in zip(data, results):
    print(x, y)
<mask token>
for i in np.arange(0, L * W):
    img = cv2.imread(data[i])
    axes[i].imshow(img)
    axes[i].set_title(results[i])
    axes[i].set_xticks([])
    axes[i].set_yticks([])
fig.tight_layout()
fig.savefig('image.png', bbox_inches='tight')

<mask token>
print(tf.__version__)
model = tf.keras.models.load_model('../model/my_model.h5', custom_objects=
    None, compile=True, options=None)
train_datagen = ImageDataGenerator(rotation_range=20, width_shift_range=0.2,
    height_shift_range=0.2, horizontal_flip=True, vertical_flip=True,
    preprocessing_function=preprocess_input, validation_split=0.2)
img_size = 150, 150
training_set = train_datagen.flow_from_directory('../dataset', target_size=
    img_size, class_mode='binary', subset='training')
testing_set = train_datagen.flow_from_directory('../dataset', target_size=
    img_size, class_mode='binary', subset='validation')
loss, acc = model.evaluate(training_set)
img_dir = '../dataset/pred/'
data_path = os.path.join(img_dir, '*.jpg')
files = glob.glob(data_path)
data = []
results = []
for file in files:
    test_images = image.load_img(file, target_size=img_size)
    test_images = image.img_to_array(test_images)
    test_images = np.expand_dims(test_images, axis=0)
    images = np.vstack([test_images])
    classes = model.predict(images, batch_size=10)
    classes = np.round(classes)
    data.append(file)
    results.append(classes)
for x, y in zip(data, results):
    print(x, y)
W = 4
L = 4
fig, axes = plt.subplots(L, W, figsize=(12, 12))
axes = axes.ravel()
for i in np.arange(0, L * W):
    img = cv2.imread(data[i])
    axes[i].imshow(img)
    axes[i].set_title(results[i])
    axes[i].set_xticks([])
    axes[i].set_yticks([])
fig.tight_layout()
fig.savefig('image.png', bbox_inches='tight')

import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing import image
import numpy as np
import matplotlib.pyplot as plt
import cv2
import os
import glob
print(tf.__version__)
model = tf.keras.models.load_model('../model/my_model.h5', custom_objects=
    None, compile=True, options=None)
train_datagen = ImageDataGenerator(rotation_range=20, width_shift_range=0.2,
    height_shift_range=0.2, horizontal_flip=True, vertical_flip=True,
    preprocessing_function=preprocess_input, validation_split=0.2)
img_size = 150, 150
training_set = train_datagen.flow_from_directory('../dataset', target_size=
    img_size, class_mode='binary', subset='training')
testing_set = train_datagen.flow_from_directory('../dataset', target_size=
    img_size, class_mode='binary', subset='validation')
loss, acc = model.evaluate(training_set)
img_dir = '../dataset/pred/'
data_path = os.path.join(img_dir, '*.jpg')
files = glob.glob(data_path)
data = []
results = []
for file in files:
    test_images = image.load_img(file, target_size=img_size)
    test_images = image.img_to_array(test_images)
    test_images = np.expand_dims(test_images, axis=0)
    images = np.vstack([test_images])
    classes = model.predict(images, batch_size=10)
    classes = np.round(classes)
    data.append(file)
    results.append(classes)
for x, y in zip(data, results):
    print(x, y)
W = 4
L = 4
fig, axes = plt.subplots(L, W, figsize=(12, 12))
axes = axes.ravel()
for i in np.arange(0, L * W):
    img = cv2.imread(data[i])
    axes[i].imshow(img)
    axes[i].set_title(results[i])
    axes[i].set_xticks([])
    axes[i].set_yticks([])
fig.tight_layout()
fig.savefig('image.png', bbox_inches='tight')

import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.preprocessing import image

# Helper libraries
import numpy as np
import matplotlib.pyplot as plt
import cv2
import os
import glob


print(tf.__version__)

model = tf.keras.models.load_model(
    '../model/my_model.h5',
    custom_objects=None,
    compile=True,
    options=None)

train_datagen = ImageDataGenerator(
    rotation_range=20,
    width_shift_range=0.2,
    height_shift_range=0.2,
    horizontal_flip=True,
    vertical_flip=True,
    preprocessing_function=preprocess_input,
    validation_split=0.2
)

img_size = (150, 150)

training_set = train_datagen.flow_from_directory(
    '../dataset',
    target_size=img_size,
    class_mode='binary',
    subset='training'
)

testing_set = train_datagen.flow_from_directory(
    '../dataset',
    target_size=img_size,
    class_mode='binary',
    subset='validation'
)

loss, acc = model.evaluate(training_set)

img_dir = "../dataset/pred/"
data_path = os.path.join(img_dir, '*.jpg')
files = glob.glob(data_path)
data = []
results = []

for file in files:
    test_images = image.load_img(file, target_size=img_size)
    test_images = image.img_to_array(test_images)
    test_images = np.expand_dims(test_images, axis=0)
    images = np.vstack([test_images])
    classes = model.predict(images, batch_size=10)
    classes = np.round(classes)
    data.append(file)
    results.append(classes)

for x, y in zip(data, results):
    print(x, y)

W = 4
L = 4
fig, axes = plt.subplots(L, W, figsize=(12, 12))
axes = axes.ravel()
for i in np.arange(0, L * W):
    img = cv2.imread(data[i])
    axes[i].imshow(img)
    axes[i].set_title(results[i])
    axes[i].set_xticks([])
    axes[i].set_yticks([])

fig.tight_layout()
fig.savefig('image.png', bbox_inches='tight')
