def calculate_the_best_weight(self): if os.listdir(checkpoint_path): value = Image_Processing.extraction_image(checkpoint_path) extract_num = [ os.path.splitext(os.path.split(i)[-1])[0] for i in value ] num = [re.split('-', i) for i in extract_num] accs = [float(i[-1]) for i in num] losses = [float('-' + str(abs(float(i[-2])))) for i in num] index = [acc + loss for acc, loss in zip(accs, losses)] model_dict = dict((ind, val) for ind, val in zip(index, value)) return model_dict.get(max(index)) else: logger.debug('没有可用的检查点')
from settings import MODEL_NAME from settings import DATA_ENHANCEMENT from settings import train_pack_path from settings import validation_pack_path from settings import test_pack_path from settings import train_enhance_path from Function_API import cheak_path from Function_API import Image_Processing from Function_API import parse_function_verification gpus = tf.config.experimental.list_physical_devices(device_type='GPU') for gpu in gpus: tf.config.experimental.set_memory_growth(device=gpu, enable=True) train_dataset = tf.data.TFRecordDataset( Image_Processing.extraction_image(train_pack_path)).map( parse_function_verification).batch(BATCH_SIZE) validation_dataset = tf.data.TFRecordDataset( Image_Processing.extraction_image(validation_pack_path)).map( parse_function_verification).batch(BATCH_SIZE) test_dataset = tf.data.TFRecordDataset( Image_Processing.extraction_image(test_pack_path)).map( parse_function_verification).batch(BATCH_SIZE) model, c_callback = CallBack.callback(operator.methodcaller(MODEL)(Model)) model.summary() model.compile(optimizer=tf.keras.optimizers.Adam(lr=1e-3, amsgrad=True),
from settings import train_path from Function_API import Image_Processing Image_Processing.rename_suffix(Image_Processing.extraction_image(train_path))
from settings import train_path from Function_API import Image_Processing Image_Processing.rename_path(train_path)
# 测试模型 import os import random import tensorflow as tf from loguru import logger from settings import BATCH_SIZE from settings import model_path from settings import test_pack_path from settings import MODEL_LEAD_NAME from settings import test_path from Function_API import Image_Processing from Function_API import Distinguish_image from Function_API import parse_function_verification gpus = tf.config.experimental.list_physical_devices(device_type='GPU') for gpu in gpus: tf.config.experimental.set_memory_growth(device=gpu, enable=True) test_dataset = tf.data.TFRecordDataset( Image_Processing.extraction_image(test_pack_path)).map( parse_function_verification).batch(BATCH_SIZE) model_path = os.path.join(model_path, MODEL_LEAD_NAME) test_image_list = Image_Processing.extraction_image(test_path) random.shuffle(test_image_list) for i in test_image_list[:50]: Distinguish_image.distinguish_image(model_path, i) model = tf.keras.models.load_model(model_path) logger.info(model.evaluate(test_dataset))
import random from settings import train_path from Function_API import Image_Processing train_image = Image_Processing.extraction_image(train_path) random.shuffle(train_image) Image_Processing.move_path(train_image)
from settings import validation_path from settings import test_path from settings import IMAGE_HEIGHT from settings import IMAGE_WIDTH from settings import train_enhance_path from settings import DATA_ENHANCEMENT from settings import TFRecord_train_path from settings import TFRecord_validation_path from settings import TFRecord_test_path from Function_API import Image_Processing from Function_API import WriteTFRecord from concurrent.futures import ThreadPoolExecutor if DATA_ENHANCEMENT: with ThreadPoolExecutor(max_workers=100) as t: for i in Image_Processing.extraction_image(train_path): task = t.submit(Image_Processing.preprosess_save_images, i, [IMAGE_HEIGHT, IMAGE_WIDTH]) train_image = Image_Processing.extraction_image(train_enhance_path) random.shuffle(train_image) train_lable = Image_Processing.extraction_one_hot_lable(train_image) else: train_image = Image_Processing.extraction_image(train_path) random.shuffle(train_image) train_lable = Image_Processing.extraction_one_hot_lable(train_image) validation_image = Image_Processing.extraction_image(validation_path) validation_lable = Image_Processing.extraction_one_hot_lable(validation_image) test_image = Image_Processing.extraction_image(test_path) test_lable = Image_Processing.extraction_one_hot_lable(test_image)