【发布时间】:2021-04-10 04:19:09
【问题描述】:
我已经训练了一个基本的图像分类器,但在尝试评估结果时遇到了一个相当基本的问题。
我正在努力加载我的验证数据的实际值和每个图像的相应文件名,以便将它们与model.predict 值进行比较。
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 3 21:21:02 2021
@author: Sam
"""
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.preprocessing.image import ImageDataGenerator
train_examples = 425
test_examples = 245
validation_examples = 245
img_height = img_width = 224
batch_size = 32
epochs = 100
model = keras.models.load_model('isic_model4/')
train_datagen = ImageDataGenerator(
rescale = 1.0/255,
rotation_range = 15,
zoom_range = (0.95, 0.95),
horizontal_flip = True,
vertical_flip = True,
data_format = "channels_last",
dtype = tf.float32,
)
validation_datagen = ImageDataGenerator(rescale=1.0/255, dtype=tf.float32)
test_datagen = ImageDataGenerator(rescale=1.0/255, dtype=tf.float32)
train_gen = train_datagen.flow_from_directory(
"ClassifierData/Training/",
target_size = (img_height, img_width),
batch_size=batch_size,
color_mode = "rgb",
class_mode = "binary",
shuffle = False,
seed = 123,
)
validation_gen = validation_datagen.flow_from_directory(
"ClassifierData/Validation/",
target_size = (img_height, img_width),
batch_size=batch_size,
color_mode = "rgb",
class_mode = "binary",
shuffle = False,
seed = 123,
)
test_gen = test_datagen.flow_from_directory(
"ClassifierData/Test/",
target_size = (img_height, img_width),
batch_size=batch_size,
color_mode = "rgb",
class_mode = "binary",
shuffle = False,
seed = 123,
)
METRICS = [
keras.metrics.BinaryAccuracy(name="accuracy"),
keras.metrics.Precision(name="precision"),
keras.metrics.Recall(name="recall"),
keras.metrics.AUC(name='auc'),
]
valpred1 = model.predict_classes(validation_gen)
【问题讨论】:
-
您是否在 Jupyter Notebook 中执行此操作?你能添加目录结构吗?
标签: tensorflow machine-learning keras deep-learning classification