↓폴밍끼 유튜브 채널 자세히보기

Python library & package/Tensorflow & keras

unet을 load_model 시 Unknown layer: GELU. Please ensure this object is passed to the `custom_objects` argument. 가 뜬다면 custom_objects 설정하세요

폴밍끼 2021. 12. 11. 14:34
728x90

아래 두 코드처럼 load_model의 인자에 모델 경로 뿐만 아니라 custom_objects도 추가해줘야 합니다.

from keras_unet_collection.activations import GELU
from keras_unet_collection.losses import iou_seg

# /media/visbic/MGTEC/water_seg/water_segmentation/unet_model/20211211-040154/10-0.9812.hdf5
model = keras.models.load_model('/water_segmentation/unet_model/20211211-040154/10-0.9812.hdf5', 
                                custom_objects={
                                                "GELU":GELU,
                                                "iou_seg":iou_seg
                                                })​

 

from keras_unet_collection.transformer_layers import patch_extract, patch_embedding
from keras_unet_collection.activations import GELU

model = keras.models.load_model('model_epoch24.h5', 
                                custom_objects={"jaccard_coef": jaccard_coef,
                                                "jaccard_coef_int":jaccard_coef_int,
                                                "GELU":GELU,
                                                "patch_extract":patch_extract, 
                                                "patch_embedding":patch_embedding,
                                                })

 

참고 : https://githubmemory.com/repo/yingkaisha/keras-unet-collection/issues/24