【问题标题】:I tried to fine-tune VGG16 on my dataset, but met the OSError about loading VGG16 weights我试图在我的数据集上微调 VGG16,但遇到了关于加载 VGG16 权重的 OSError
【发布时间】:2021-06-29 03:42:45
【问题描述】:

我尝试在我的数据集上微调 VGG16,但在打开 VGG16-weights 的 h5py 文件时遇到了麻烦。我不明白这个错误是什么意思:

OSError: Unable to open file (Truncated file: eof = 221184, sblock->base_addr = 0, stored_eoa = 58889256)

有人知道怎么解决吗?谢谢

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-3-6059faca8ed7> in <module>()
      9     K.set_session(sess)
     10     input_tensor=Input(shape=(h,w,ch))
---> 11     base_model=VGG16(input_tensor=input_tensor, include_top=False)
     12     x_img=base_model.output
     13     x_img=AveragePooling2D((7,7))(x_img)

/Users/simin/anaconda/envs/IntroToTensorFlow/lib/python3.5/site-packages/keras/applications/vgg16.py in VGG16(include_top, weights, input_tensor)
    144                                         TF_WEIGHTS_PATH_NO_TOP,
    145                                         cache_subdir='models')
--> 146             model.load_weights(weights_path)
    147             if K.backend() == 'theano':
    148                 convert_all_kernels_in_model(model)

/Users/simin/anaconda/envs/IntroToTensorFlow/lib/python3.5/site-packages/keras/engine/topology.py in load_weights(self, filepath, by_name)
   2492         '''
   2493         import h5py
-> 2494         f = h5py.File(filepath, mode='r')
   2495         if 'layer_names' not in f.attrs and 'model_weights' in f:
   2496             f = f['model_weights']

/Users/simin/anaconda/envs/IntroToTensorFlow/lib/python3.5/site-packages/h5py/_hl/files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, **kwds)
    270 
    271                 fapl = make_fapl(driver, libver, **kwds)
--> 272                 fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
    273 
    274                 if swmr_support:

/Users/simin/anaconda/envs/IntroToTensorFlow/lib/python3.5/site-packages/h5py/_hl/files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
     90         if swmr and swmr_support:
     91             flags |= h5f.ACC_SWMR_READ
---> 92         fid = h5f.open(name, flags, fapl=fapl)
     93     elif mode == 'r+':
     94         fid = h5f.open(name, h5f.ACC_RDWR, fapl=fapl)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/work/h5py/_objects.c:2696)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/Users/ilan/minonda/conda-bld/work/h5py/_objects.c:2654)()

h5py/h5f.pyx in h5py.h5f.open (/Users/ilan/minonda/conda-bld/work/h5py/h5f.c:1942)()

OSError: Unable to open file (Truncated file: eof = 221184, sblock->base_addr = 0, stored_eoa = 58889256)

【问题讨论】:

标签: python keras h5py


【解决方案1】:

文件下载可能失败。

用以下文件替换打开失败的文件可能会解决它。 https://github.com/fchollet/deep-learning-models/releases

我的情况, 该文件位于以下路径中。 C:\Users\MyName\.keras\models\vgg16_weights_tf_dim_ordering_tf_kernels.h5

我换掉了,解决了。

【讨论】:

    【解决方案2】:

    因为您上次下载文件失败。但坏文件仍保留在文件路径中。所以你必须找到坏文件。 也许你可以使用“find / -name 'vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5'”在 unix 系统中查找路径。 然后删除它 试试agian!祝你好运!!

    【讨论】:

      【解决方案3】:

      可能是文件下载失败或文件损坏。

      我在/tmp/.keras/models/vggface/ 中找到了那些损坏的文件。

      我的系统是 Ubuntu 20.04。

      【讨论】:

        猜你喜欢
        • 2020-03-15
        • 2018-12-24
        • 1970-01-01
        • 2017-09-09
        • 2020-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-09
        相关资源
        最近更新 更多