1.训练过程: from tensorflow.keras.preprocessing.image import ImageDataGenerator from tensorflow.keras.applications.xception import Xception from tensorflow.keras.layers import GlobalAveragePooling2D, GlobalMaxPooling2D, Dense, Flatten, Input, Concatenate, Dropout from tensorflow.keras.models import Model import tensorflow as tf from tensorflow.keras.callbacks import ModelCheckpoint,ReduceLROnPlateau,TensorBoard, EarlyStopping from sklearn.utils import class_weight import numpy as np # 下面的一部分是进行数据预处理 import os import shutil def image_number(dir_path): path = [] for dir, file, images in os.walk(dir_path): for image in images: if image.endswith(".bmp") or image.endswith(".jpg")or image.endswith(".jpeg"): imagepath = os.path.join(dir, image) path.append(imagepath) return path training_path=r".\training" eval_path =r".\validation" test_path=r".\test" MODEL_path=r".\model" log_path=r".\log" training_image_path = image_number(training_path) # 训练集数据路径列表 val_image_path = image_number(eval_path) #test_image_path=image_number(test_path) label=["defect","dust","ok"] #label=["defect","ok"] training_image_number = len(training_image_path) # 训练集数据量 val_image_number = len(val_image_path) #test_image_number=len(test_image_path) classfication_number = len(label) # 分类数 batch=16 train_epoch = (training_image_number // batch) val_epoch = (val_ima
使用Tensorflow2.0和Keras训练分类模型实例
最新推荐文章于 2022-12-29 15:13:54 发布
本文通过实例详细介绍了如何利用Python的Tensorflow2.0和Keras库训练一个分类模型,涵盖了深度学习和计算机视觉的基本应用。
摘要由CSDN通过智能技术生成