python/tensorflow,keras4 keras one-hot encoding from tensorflow.keras.utils import to_categorical train_y = to_categorical(train_y) test_y = to_categorical(test_y) print(train_y.shape, test_y.shape) 2022. 10. 5. tensorflow.keras.callbacks 1. EarlyStopping 일정 기준을 만족하면 학습을 정지함 model.fit(callbacks = [early_stopping]) 2. ModelCheckpoint 일정 기준을 만족하면 가중치를 저장함 from tensorflow.keras.callbacks import ModelCheckpoint, EarlyStopping early_stopping = EarlyStopping(monitor = 'val_loss', min_delta = 0, patience = 3, verbose = 1, restore_best_weights = True) checkpoint = ModelCheckpoint(monitor = "val_loss", filepath = MODEL_PATH, save_best_onl.. 2022. 10. 1. 학습한 모델 저장 1. 모델 + 가중치 저장하기 >> h5 MODEL_PATH = "/model" model.save(MODEL_PATH + "model.h5") new_model = tf.keras.models.load_model(MODEL_PATH + "model.h5") test_loss, test_acc = new_model.evaluate(x, y, verbose=2) 2. 가중치만 저장하기 2-1. save_weights() >> h5 model.save_weights("model_weight") new_model = tf.keras.models.Sequential([ tf.keras.layers.Input() ... ]) new_model.load_weights("model_weights") test_loss.. 2022. 10. 1. keras ImageDataGenerator 1. ImageDataGenerator 선언 import tensorflow as tf from tensorflow import keras from keras.preprocessing.image import ImageDataGenerator batch_size = 16 img_height = 96 img_width = 200 train_datagen = ImageDataGenerator( rescale = 1./ 255, # 이미지 데이터 정규화 validation_split = 0.2, # train, validation 데이터 분할 (8:2) ) train_generator = train_datagen.flow_from_directory( TRAIN_PATH, batch_size=batch_size,.. 2022. 10. 1. 이전 1 다음