7 Star 51 Fork 15

肆十二/Flower_tf2.3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test_model.py 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
NULL 提交于 2020-12-12 19:09 . '花卉识别第一次上传'
import tensorflow as tf
# 数据加载,按照8:2的比例加载花卉数据
def data_load(data_dir, img_height, img_width, batch_size):
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
label_mode='categorical',
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
label_mode='categorical',
validation_split=0.2,
subset="validation",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
class_names = train_ds.class_names
return train_ds, val_ds, class_names
def test(is_transfer=True):
train_ds, val_ds, class_names = data_load("../data/flower_photos", 224, 224, 4)
if is_transfer:
model = tf.keras.models.load_model("models/mobilenet_flower.h5")
else:
model = tf.keras.models.load_model("models/cnn_flower.h5")
model.summary()
loss, accuracy = model.evaluate(val_ds)
print('Test accuracy :', accuracy)
if __name__ == '__main__':
test(True)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/song-laogou/Flower_tf2.3.git
git@gitee.com:song-laogou/Flower_tf2.3.git
song-laogou
Flower_tf2.3
Flower_tf2.3
master

搜索帮助