Minor modification to remove pylint messages

This commit is contained in:
Heiko J Schick
2020-10-08 16:43:50 +02:00
parent 1db90f8a0a
commit d081002d5e
3 changed files with 94 additions and 93 deletions
+30 -24
View File
@@ -1,5 +1,11 @@
import keras
from keras.models import Model, load_model
"""
Simple example on how to fine tune models in Keras and how to use them.
Part 1
Source: https://www.guru99.com/keras-tutorial.html
"""
from keras.models import load_model
from keras.preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
import numpy as np
@@ -9,40 +15,45 @@ train_datagen = ImageDataGenerator(validation_split=0.3,
zoom_range=0.2,
horizontal_flip=True)
train_path = 'images/train/'
test_path = 'images/test/'
batch_size = 16
image_size = 224
num_class = 8
TRAIN_PATH = 'images/train/'
TEST_PATH = 'images/test/'
BATCH_SIZE = 16
IMAGE_SIZE = 224
NUM_CLASSES = 8
### Testing our model
model = load_model('fine_tune.h5')
test_datagen = ImageDataGenerator()
train_generator = train_datagen.flow_from_directory(
directory=train_path,
target_size=(image_size,image_size),
batch_size=batch_size,
directory=TRAIN_PATH,
target_size=(IMAGE_SIZE, IMAGE_SIZE),
batch_size=BATCH_SIZE,
class_mode='categorical',
color_mode='rgb',
shuffle=True)
test_generator = test_datagen.flow_from_directory(
directory=test_path,
target_size=(image_size, image_size),
directory=TEST_PATH,
target_size=(IMAGE_SIZE, IMAGE_SIZE),
color_mode='rgb',
shuffle=False,
class_mode='categorical',
batch_size=1)
filenames = test_generator.filenames
filenames = test_generator.filenames
nb_samples = len(filenames)
fig=plt.figure()
columns = 4
rows = 4
for i in range(1, columns*rows -1):
x_batch, y_batch = test_generator.next()
fig = plt.figure()
COLUMNS = 4
ROWS = 4
# And our test is as given below! Only 1 image is predicted wrong from a test of
# 14 images!
for i in range(1, COLUMNS*ROWS -1):
x_batch, y_batch = next(test_generator)
name = model.predict(x_batch)
name = np.argmax(name, axis=-1)
@@ -55,12 +66,7 @@ for i in range(1, columns*rows -1):
true_value = [label_map[k] for k in true_name]
image = x_batch[0].astype(np.int)
fig.add_subplot(rows, columns, i)
fig.add_subplot(ROWS, COLUMNS, i)
plt.title(str(predictions[0]) + ':' + str(true_value[0]))
plt.imshow(image)
plt.show()
'''
And our test is as given below! Only 1 image is predicted wrong from a test of
14 images!
'''