인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

안재형 AN님의 프로필 이미지
안재형 AN

작성한 질문수

[개정판] 딥러닝 컴퓨터 비전 완벽 가이드

keras-yolo 모델 로드 시 에러가 발생합니다.

작성

·

2.7K

0

KerasYolo_이미지와 영상_Detection.ipynb 파일 내에서 yolo.h5 모델 load시 아래와 같은 에러가 발생합니다.

OSError: Unable to open file (unable to open file: name = '~/OneDrive/workspace/DLCV/Detection/yolo/keras-yolo3/model_data/yolo.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

(windows 환경의 GPU가 달린 장비를 사용하고 있어서 경로는 저의 개인 컴퓨터 경로에 맞추었습니다.) 

경로는 잘 잡은 것 같은데 file을 열 수 없다고 합니다.. 버전 문제인가 싶어 tensorflow 1.13, 1.15에서 모두 시도해봤는데 동일한 문제가 발생합니다. 

아래는 전체 에러 출력 내용입니다.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\OneDrive\workspace\DLCV\Detection\yolo\keras-yolo3\yolo.py in generate(self)
     69         try:
---> 70             self.yolo_model = load_model(model_path, compile=False)
     71         except:

~\miniconda3\envs\env_vision\lib\site-packages\keras\models.py in load_model(filepath, custom_objects, compile)
    242         model_config = json.loads(model_config.decode('utf-8'))
--> 243         model = model_from_config(model_config, custom_objects=custom_objects)
    244 

~\miniconda3\envs\env_vision\lib\site-packages\keras\models.py in model_from_config(config, custom_objects)
    316                         '`Sequential.from_config(config)`?')
--> 317     return layer_module.deserialize(config, custom_objects=custom_objects)
    318 

~\miniconda3\envs\env_vision\lib\site-packages\keras\layers\__init__.py in deserialize(config, custom_objects)
     54                                     custom_objects=custom_objects,
---> 55                                     printable_module_name='layer')

~\miniconda3\envs\env_vision\lib\site-packages\keras\utils\generic_utils.py in deserialize_keras_object(identifier, module_objects, custom_objects, printable_module_name)
    137                 raise ValueError('Unknown ' + printable_module_name +
--> 138                                  ': ' + class_name)
    139         if hasattr(cls, 'from_config'):

ValueError: Unknown layer: Functional

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-6-4f077c0b45b9> in <module>
     10             anchors_path='~/OneDrive/workspace/DLCV/Detection/yolo/keras-yolo3/model_data/yolo_anchors.txt',
     11             classes_path='~/OneDrive/workspace/DLCV/Detection/yolo/keras-yolo3/model_data/coco_classes.txt',
---> 12             score=0.6)

~\OneDrive\workspace\DLCV\Detection\yolo\keras-yolo3\yolo.py in __init__(self, **kwargs)
     43         self.anchors = self._get_anchors()
     44         self.sess = K.get_session()
---> 45         self.boxes, self.scores, self.classes = self.generate()
     46 
     47     def _get_class(self):

~\OneDrive\workspace\DLCV\Detection\yolo\keras-yolo3\yolo.py in generate(self)
     72             self.yolo_model = tiny_yolo_body(Input(shape=(None,None,3)), num_anchors//2, num_classes) \
     73                 if is_tiny_version else yolo_body(Input(shape=(None,None,3)), num_anchors//3, num_classes)
---> 74             self.yolo_model.load_weights(self.model_path) # make sure model, anchors and classes match
     75         else:
     76             assert self.yolo_model.layers[-1].output_shape[-1] == \

~\miniconda3\envs\env_vision\lib\site-packages\keras\engine\topology.py in load_weights(self, filepath, by_name, skip_mismatch, reshape)
   2645         if h5py is None:
   2646             raise ImportError('`load_weights` requires h5py.')
-> 2647         with h5py.File(filepath, mode='r') as f:
   2648             if 'layer_names' not in f.attrs and 'model_weights' in f:
   2649                 f = f['model_weights']

~\miniconda3\envs\env_vision\lib\site-packages\h5py\_hl\files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, rdcc_nslots, rdcc_nbytes, rdcc_w0, track_order, **kwds)
    406                 fid = make_fid(name, mode, userblock_size,
    407                                fapl, fcpl=make_fcpl(track_order=track_order),
--> 408                                swmr=swmr)
    409 
    410             if isinstance(libver, tuple):

~\miniconda3\envs\env_vision\lib\site-packages\h5py\_hl\files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
    171         if swmr and swmr_support:
    172             flags |= h5f.ACC_SWMR_READ
--> 173         fid = h5f.open(name, flags, fapl=fapl)
    174     elif mode == 'r+':
    175         fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)

h5py\_objects.pyx in h5py._objects.with_phil.wrapper()

h5py\_objects.pyx in h5py._objects.with_phil.wrapper()

h5py\h5f.pyx in h5py.h5f.open()

OSError: Unable to open file (unable to open file: name = '~/OneDrive/workspace/DLCV/Detection/yolo/keras-yolo3/model_data/yolo.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

답변 1

0

권 철민님의 프로필 이미지
권 철민
지식공유자

안녕하십니까,

'~/OneDrive/workspace/DLCV/Detection/yolo/keras-yolo3/model_data/yolo.h5' 일때

모델파일 ~ 표시인 Home Directory를 인식하지 못하는것 같습니다. 절대 경로로 변환하신 후 다시 시도해 보시지요.

감사합니다.

from yolo import YOLO에서 계속 cannot import name 'YOLO' from 'yolo' 에러가 생기는데 어떻게 해결하셨나요?

 

from yolo3.model import preprocess_true_boxes, yolo_body, tiny_yolo_body, yolo_loss from yolo3.utils import get_random_data 도 계속 ImportError: cannot import name 'compose' from 'yolo3.utils' 에러가 발생하는데 어떻게 해결해야 하는지 도움 주시면 감사합니다.

권 철민님의 프로필 이미지
권 철민
지식공유자

안녕하십니까, 

음, 과거 버전 Keras Yolo를 사용하기를 원하시는 건가요? 

저도 이제 Keras Yolo를 사용해본지가 너무 오래되서 기억이 잘 나지 않아서 도움이 될지 모르겠습니다. 

암튼, 여기에 글을 올리시면 원본 글 수강생이신 안재형님에게도 메일이 가니까, 따로 질의를 올려주시지요. 

그리고 어떤 환경에서 작업을 하시는지, 코랩인지 개인 pc의 jupyter notebook인지 명시해 주시고, 오류 메시지 전체를 올려 주십시요. 

https://www.inflearn.com/questions/616697 질문 올렸습니다.

 

안재형 AN님의 프로필 이미지
안재형 AN

작성한 질문수

질문하기