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 works.project_12306_ocr.settings import train_path from works.project_12306_ocr.Function_API import Image_Processing Image_Processing.rename_suffix(Image_Processing.extraction_image(train_path))
from works.project_12306_ocr.Callback import CallBack from works.project_12306_ocr.settings import MODEL from works.project_12306_ocr.settings import MODEL_NAME from works.project_12306_ocr.settings import checkpoint_path from works.project_12306_ocr.settings import App_model_path from works.project_12306_ocr.settings import MULITI_MODEL_PREDICTION from works.project_12306_ocr.Function_API import Distinguish_image from works.project_12306_ocr.Function_API import Image_Processing gpus = tf.config.experimental.list_physical_devices(device_type='GPU') for gpu in gpus: tf.config.experimental.set_memory_growth(device=gpu, enable=True) app = Flask(__name__) if os.listdir(App_model_path): model_path = Image_Processing.extraction_image(App_model_path) logger.debug(f'{model_path}模型加载成功') else: model = operator.methodcaller(MODEL)(Models) try: model.load_weights(os.path.join(checkpoint_path, CallBack.calculate_the_best_weight())) except: raise OSError(f'没有任何的权重和模型在{App_model_path}') model_save = os.path.join(App_model_path, MODEL_NAME) model.save(model_save) model_path = [model_save] logger.debug(f'{model_path}模型加载成功') # logger.debug(model_path)
import random from works.project_12306_ocr.settings import train_path from works.project_12306_ocr.Function_API import Image_Processing train_image = Image_Processing.extraction_image(train_path) random.shuffle(train_image) Image_Processing.move_path(train_image)
from works.project_12306_ocr.settings import DATA_ENHANCEMENT from works.project_12306_ocr.settings import train_path from works.project_12306_ocr.settings import train_pack_path from works.project_12306_ocr.settings import validation_pack_path from works.project_12306_ocr.settings import test_pack_path from works.project_12306_ocr.settings import train_enhance_path from works.project_12306_ocr.Function_API import cheak_path from works.project_12306_ocr.Function_API import Image_Processing from works.project_12306_ocr.Function_API import parse_function_ocr 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_ocr).batch(BATCH_SIZE) validation_dataset = tf.data.TFRecordDataset( Image_Processing.extraction_image(validation_pack_path)).map( parse_function_ocr).batch(BATCH_SIZE) test_dataset = tf.data.TFRecordDataset( Image_Processing.extraction_image(test_pack_path)).map( parse_function_ocr).batch(BATCH_SIZE) logger.debug(train_dataset) model, c_callback = CallBack.callback(operator.methodcaller(MODEL)(Models)) model.summary()
from works.project_12306_ocr.settings import train_path from works.project_12306_ocr.Function_API import Image_Processing Image_Processing.rename_path(train_path)
from works.project_12306_ocr.settings import validation_path from works.project_12306_ocr.settings import test_path from works.project_12306_ocr.settings import IMAGE_HEIGHT from works.project_12306_ocr.settings import IMAGE_WIDTH from works.project_12306_ocr.settings import train_enhance_path from works.project_12306_ocr.settings import DATA_ENHANCEMENT from works.project_12306_ocr.settings import TFRecord_train_path from works.project_12306_ocr.settings import TFRecord_validation_path from works.project_12306_ocr.settings import TFRecord_test_path from works.project_12306_ocr.Function_API import Image_Processing from works.project_12306_ocr.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) Image_Processing.save_ocr_class(train_image) random.shuffle(train_image) train_lable = Image_Processing.extraction_ocr_lable(train_image) else: train_image = Image_Processing.extraction_image(train_path) Image_Processing.save_ocr_class(train_image) random.shuffle(train_image) train_lable = Image_Processing.extraction_ocr_lable(train_image) validation_image = Image_Processing.extraction_image(validation_path) validation_lable = Image_Processing.extraction_ocr_lable(validation_image)
from works.project_12306_ocr.settings import test_path from works.project_12306_ocr.settings import model_path from works.project_12306_ocr.settings import BATCH_SIZE from works.project_12306_ocr.settings import test_pack_path from works.project_12306_ocr.settings import MODEL_LEAD_NAME from works.project_12306_ocr.settings import MULITI_MODEL_PREDICTION from works.project_12306_ocr.Function_API import Image_Processing from works.project_12306_ocr.Function_API import Distinguish_image from works.project_12306_ocr.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) test_image_list = Image_Processing.extraction_image(test_path) random.shuffle(test_image_list) if MULITI_MODEL_PREDICTION: model_path = Image_Processing.extraction_image(model_path) if not model_path: raise OSError(f'{model_path}没有模型') for i in test_image_list[:10]: Distinguish_image.distinguish_images(model_path, i) else: model_path = os.path.join(model_path, MODEL_LEAD_NAME) logger.debug(f'加载模型{model_path}') if not os.path.exists(model_path):