首页 > 解决方案 > 没有这样的文件或目录:pretrained_yolov3.h5

问题描述

我尝试使用预训练的 YOLO 模型来完成我的作业,但遇到了以下错误。

OSError                                   Traceback (most recent call last)
<ipython-input-29-40f01161449a> in <module>
      5 trainer.setDataDirectory(data_directory=path)
      6 trainer.setTrainConfig(object_names_array=["Table"], batch_size=16, num_experiments=200, train_from_pretrained_model="pretrained_yolov3.h5")
----> 7 trainer.trainModel()

~\AppData\Roaming\Python\Python38\site-packages\imageai\Detection\Custom\__init__.py in trainModel(self)
    284         )"""
    285 
--> 286         train_model, infer_model = self._create_model(
    287             nb_class=len(labels),
    288             anchors=self.__model_anchors,

~\AppData\Roaming\Python\Python38\site-packages\imageai\Detection\Custom\__init__.py in _create_model(self, nb_class, anchors, max_box_per_image, max_grid, batch_size, warmup_batches, ignore_thresh, multi_gpu, lr, grid_scales, obj_scale, noobj_scale, xywh_scale, class_scale)
    588             if self.__training_mode:
    589                 print("Training with transfer learning from pretrained Model")
--> 590             template_model.load_weights(self.__pre_trained_model, by_name=True)
    591         else:
    592             if self.__training_mode:

~\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\keras\engine\training.py in load_weights(self, filepath, by_name, skip_mismatch, options)
   2225           'first, then load the weights.')
   2226     self._assert_weights_created()
-> 2227     with h5py.File(filepath, 'r') as f:
   2228       if 'layer_names' not in f.attrs and 'model_weights' in f:
   2229         f = f['model_weights']

C:\ProgramData\Anaconda3\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)
    404             with phil:
    405                 fapl = make_fapl(driver, libver, rdcc_nslots, rdcc_nbytes, rdcc_w0, **kwds)
--> 406                 fid = make_fid(name, mode, userblock_size,
    407                                fapl, fcpl=make_fcpl(track_order=track_order),
    408                                swmr=swmr)

C:\ProgramData\Anaconda3\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 = 'pretrained_yolov3.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

我使用 Windows 10 作为我的操作系统,并尝试了提到的其他解决方案但失败了。任何帮助表示赞赏

标签: pythonyoloh5py

解决方案


trainer.setTrainConfig(object_names_array=["Table"], batch_size=16, num_experiments=200, train_from_pretrained_model="pretrained_yolov3.h5")

这里在 train_from_pretrained_model= 中提供 yolov3.h5 路径。

如果您使用的是 google colab,请使用

/content/drive/MyDrive/path/pretrained-yolov3.h5

推荐阅读