-
ex09) dense Resnet 문제 해결 법카테고리 없음 2022. 2. 5. 13:20
이 오류를 해결하기 위해서 dense 에 클래스 1로 설정하였는데
나는 두개로 분류해야 하는데 어떻게 해야하지..???
from tensorflow.keras.utils import to_categorical one_hot = to_categorical(label_batch) one_hot = to_categorical(image_batch)
일단이걸로 배치들을 0,1로 만들어준다...--> 이 과정빼고 하면 어떻게 되지?? --> 상관없이 동작한다.
결국 클래스와 동일한 출력을 가지려면 네트워크를 축소해야 합니다. 예를 들어, 숫자에 대해 OCR을 수행하면 Dense(10)의 최종 출력이 필요하고 최종 출력이 됩니다(숫자 0에서 9까지).
-1을 해야되서 1을 dense output 에 넣어준다.
x = layers.Dense( 1,# 2개의클래스는 1로 세팅하도록 한다!!! 중요한 파트이다.이진분류 kernel_initializer=initializers.RandomNormal(stddev=0.01), kernel_regularizer=_gen_l2_regularizer(use_l2_regularizer), bias_regularizer=_gen_l2_regularizer(use_l2_regularizer), name='fc1000')( x) # A softmax that is followed by the model loss must be done cannot be done # in float16 due to numeric issues. So we pass dtype=float32. x = layers.Activation('sigmoid', dtype='float32')(x) #마지막 레이어 outp에서 출력 뉴런이 하나만 있을 때 softmax를 사용하고 있습니다. 'sigmoid'로 변경하는 것이 유용할 수 있습니다. #이진분류문제이기 때문에 sigmoid 를 씁니다. https://github.com/keras-team/keras/issues/1597 # Create model. return models.Model(img_input, x, name='resnet50') # Create model.
---------------------------------------------------------------------------------------------------------------
Resnet 에서 정확도 안올라가고 고정되는 문제 해결법
1. lr을 아주 낮춰본다
2. dense ouput dim = 1 로 둔다.
3.softmax 가 아니라 sigmoid로 활성화 함수를 둔다.
----------------------------------------------------------------------------------------------------------------
밑은 참고 사이트
https://github.com/keras-team/keras/issues/1597
# 콜백 정의 reduceLR = ReduceLROnPlateau( monitor='val_loss', # 검증 손실을 기준으로 callback이 호출됩니다 factor=0.5, # callback 호출시 학습률을 1/2로 줄입니다 patience=10, # epoch 10 동안 개선되지 않으면 callback이 호출됩니다 )
lr_scheduler = tf.keras.callbacks.ReduceLROnPlateau(factor=0.7, monitor='val_loss', patience=1, verbose=2, min_lr=1e-8)
lr_scheduler = tf.keras.callbacks.ReduceLROnPlateau(factor=0.7,
monitor='val_loss',#--> 'val_acc' 로 바꿔볼것
patience=1,
verbose=2,
min_lr=1e-8# learning rate 하한선 지정 )
오류 해결 전(dense output class =2 일 때_ ) 오류해결 후
오렌지색-->
빨간색 (lr 스케쥴러) -->
lr 스케쥴러로 확인했을때 수렴하는 것이 장점이나, 정확도가 줄어드는것이 확인되었다
그래프론 더 나은데 왜 저 코드에서 나온 정확도가 낮은 걸까 ??????????
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
폐렴 진단 깃 허브 주소:
https://github.com/Futuremine97/-EX-09-/blob/main/EX09%20Resnet_0206.ipynb
GitHub - Futuremine97/-EX-09-
Contribute to Futuremine97/-EX-09- development by creating an account on GitHub.
github.com