np.load()报错ValueError: Object arrays cannot be loaded when allow_pickle=False

代码
 weights = np.load(local_weights_file, encoding='bytes').item()
报错信息
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-db8068d82fff> in <module>()
----> 1 pretrained_weights, readable_labels = helpers_06.fetch_alexnet_weights_and_classes()

 in fetch_alexnet_weights_and_classes()
     52     local_labels_file = maybe_download(remote_labels_file, url, directory)
     53 
---> 54     weights = np.load(local_weights_file, encoding='bytes').item()
     55 
     56     # ugly:  but that's how guerzhoy provides the names

~/.local/lib/python3.6/site-packages/numpy/lib/npyio.py in load(file, mmap_mode, allow_pickle, fix_imports, encoding)
    438             else:
    439                 return format.read_array(fid, allow_pickle=allow_pickle,
--> 440                                          pickle_kwargs=pickle_kwargs)
    441         else:
    442             # Try a pickle

~/.local/lib/python3.6/site-packages/numpy/lib/format.py in read_array(fp, allow_pickle, pickle_kwargs)
    725         # The array contained Python objects. We need to unpickle the data.
    726         if not allow_pickle:
--> 727             raise ValueError("Object arrays cannot be loaded when "
    728                              "allow_pickle=False")
    729         if pickle_kwargs is None:

ValueError: Object arrays cannot be loaded when allow_pickle=False

解决方法

 weights = np.load(local_weights_file, encoding='bytes' ,allow_pickle=True).item()

np.load() 加入 allow_pickle=True

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐