본문 바로가기

Keras6

KT AIVLE School 7주차 정리 - 전이 학습과 파인 튜닝 전이 학습과 파인 튜닝을 하는 방법은 정말 쉬웠습니다. 배우면서도 엄청 간단해서 이래도 되나 싶을 정도였습니다. 하지만 저의 수준과 경험으로는 파인 튜닝을 통해 성능을 올리는 것은 어렵다는 것을 알게 되었고, 인터넷을 봐도 이러한 정보는 다 꽁꽁 숨겨놓거나 데이터마다 다르기 때문에 여러방면에 경험을 많이 해야겠습니다! 전이 학습하는 코드 틀 https://keras.io/guides/sequential_model/ # Load a convolutional base with pre-trained weights base_model = keras.applications.Xception( weights='imagenet', include_top=False, pooling='avg') # Freeze the ba.. 2023. 3. 15.
KT AIVLE School 7주차 정리 - 상황별 Data Augmentation 미니프로젝트 때 꼭 사용되는 ImageDataGenerator에 대해서 정확하게 알지 못하다보니, 팀원간에 이미지 데이터를 전처리하는 방식에 따라서 Data Augmentation하는 방식이 달라 헤맸던 기억이 있어서 후에 상황별로 정리를 합니다! x_train, y_train 데이터가 이미 있을 때 합치는 방법 train_datagen = ImageDataGenerator(rotation_range=20, width_shift_range=0.1, height_shift_range=0.1, zoom_range=0.1, shear_range=0.1, horizontal_flip=True, vertical_flip=True) # 데이터 증강한 훈련용 이미지 데이터 셋 생성 train_datagen.fit(x.. 2023. 3. 15.
KT AIVLE School 7주차 정리 - CNN 모델 만들고 사용하기 이미지 전처리는 제일 밑에 링크를 걸어 둔 곳으로 가서 보시면 됩니다! 이미지 경로를 train, valid, test 폴더로 정리한 후 데이터 로드 def make_x_dataset(train_path, valid_path, test_path): for indx, path in enumerate([train_path, valid_path, test_path]): Images = [] for img_path in os.listdir(path): img = load_img(path + img_path, target_size=(IMG_SIZE, IMG_SIZE)) img = img_to_array(img) Images.append(img) if indx == 0: x_train = np.array(Image.. 2023. 3. 15.
KT AIVLE School 7주차 정리 - Keras callbacks 미니 프로젝트 중에 같은 팀원이 다른 callback 함수를 사용한 코드를 제공해서 똑같은 상황에서 학습돌려보는 취지로 사용했었는데 좀더 나은 성능이 나오는 것을 보고 한번 정리해보자는 마음에 가장 많이 사용되는 3가지를 기록합니다! EarlyStopping from tensorflow.keras.callbacks import EarlyStopping es_cb = EarlyStopping(monitor='val_loss', # 모니터링할 값 min_delta=0, # 모니터링할 값의 최소 변화량 기준 patience=10, # 참는 횟수 mode='min', # 모니터링할 값의 기준 restore_best_weights=True, # 최고 성능인 가중치를 model.fit에 반환 유무 설정 verbos.. 2023. 3. 15.
KT AIVLE School 5주차 정리 - Keras (Functional) 기본 Functional API 방식 keras.backend.clear_session() # 모델 저장된 메모리 초기화 """ Sequential과의 차이점 - 변수에 각 레이어의 결과를 담는다. - 모델 변수를 처음과 끝 레이어 변수를 넣어서 따로 선언한다. - Concatenate 등과 같이 히든레이어의 설정이 가능 """ il = keras.layers.Input(shape=(1,)) hi = keras.layers.Dense(512, activation='swish', name='hidden1')(il) hi = keras.layers.Dense(256, activation='swish', name='hidden2')(hi) hi = keras.layers.Dense(128, activation.. 2023. 3. 3.
KT AIVLE School 5주차 정리 - Keras (Sequential) 모듈 가져오기 import numpy as np import pandas as pd import tensorflow as tf from tensorflow import keras x, y 분리 target = '컬럼명' x = data.drop(target, axis=1) y = data.loc[:, target] 학습, 평가 데이터 분리 from sklearn.model_selection import train_test_split x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=1) x_train.shape, x_test.shape, y_train.shape, y_test.shape 회귀 문제 - .. 2023. 2. 28.