Python 如何修复sketch_rnn算法中的“当allow_pickle = False时无法加载对象数组”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/55824625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix 'Object arrays cannot be loaded when allow_pickle=False' in the sketch_rnn algorithm
提问by Duncan Jerry
I was running the sketch_rnn.ipynb on my jupyter notebook, upon loading the environment to load the trained dataset, it returned an error 'Object arrays cannot be loaded when allow_pickle=False'
我在我的 jupyter 笔记本上运行 Sketch_rnn.ipynb,在加载环境以加载经过训练的数据集时,它返回一个错误“当 allow_pickle=False 时无法加载对象数组”
This is the code already used by google developers in developing the sketch_rnn algorithm that was even run in the google colab. In the past i have ran it myself on the google colab it worked but seems not to be working on my own jupyter notebook
这是谷歌开发人员在开发甚至在谷歌colab中运行的sketch_rnn算法时已经使用的代码。过去,我自己在 google colab 上运行过它,但似乎没有在我自己的 jupyter 笔记本上运行
from magenta.models.sketch_rnn.sketch_rnn_train import *
from magenta.models.sketch_rnn.model import *
from magenta.models.sketch_rnn.utils import *
from magenta.models.sketch_rnn.rnn import *
model_params.batch_size = 1
eval_model_params = sketch_rnn_model.copy_hparams(model_params)
eval_model_params.use_input_dropout = 0
eval_model_params.use_recurrent_dropout = 0
eval_model_params.use_output_dropout = 0
eval_model_params.is_training = 0
sample_model_params = sketch_rnn_model.copy_hparams(eval_model_params)
sample_model_params.max_seq_len = 1
return [model_params, eval_model_params, sample_model_params]
[train_set, valid_set, test_set, hps_model, eval_hps_model,
sample_hps_model] = load_env_compatible(data_dir, model_dir)
i expected the output to be
我希望输出是
INFO:tensorflow:Downloading http://github.com/hardmaru/sketch-rnn-
datasets/raw/master/aaron_sheep/aaron_sheep.npz
INFO:tensorflow:Loaded 7400/300/300 from aaron_sheep.npz
INFO:tensorflow:Dataset combined: 8000 (7400/300/300), avg len 125
INFO:tensorflow:model_params.max_seq_len 250.
total images <= max_seq_len is 7400
total images <= max_seq_len is 300
total images <= max_seq_len is 300
INFO:tensorflow:normalizing_scale_factor 18.5198.
But it gave me
但它给了我
ValueError: Object arrays cannot be loaded when allow_pickle=False
回答by Salomon Kabongo
This code solved the problem at my side.
这段代码解决了我这边的问题。
# Downgrate numpy to fix a problem
!pip install numpy==1.16.2
import numpy as np
print(np.__version__)
I just downgrade numpy as the problem is due to some internal conflict.
我只是将 numpy 降级,因为问题是由于一些内部冲突造成的。
回答by Madhuparna Bhowmik
Use allow_pickle=True as one of the arguments to np.load().
使用 allow_pickle=True 作为 np.load() 的参数之一。
回答by Bryan W
So I believe this has just surfaced due to a change in numpy to load(), if you observe the line that the error occurs it references something like
所以我相信这只是由于 numpy 到 load() 的变化而浮出水面,如果你观察到错误发生的那一行,它引用了类似的东西
with np.load(path) as f:
x_train, labels_train = f['x_train'], f['y_train']
x_test, labels_test = f['x_test'], f['y_test']
but the Keras source code, for example here at line 58: https://github.com/keras-team/keras/blob/master/keras/datasets/imdb.py
但是 Keras 源代码,例如这里的第 58 行:https: //github.com/keras-team/keras/blob/master/keras/datasets/imdb.py
now uses
现在使用
with np.load(path, allow_pickle=True) as f:
x_train, labels_train = f['x_train'], f['y_train']
x_test, labels_test = f['x_test'], f['y_test']
where np.load(path)
becomes np.load(path, boolean)
哪里np.load(path)
变成np.load(path, boolean)
From brief reading, the addition of pickles
has to do with security, since pickles
can contain arbitrary Python code that would be run when something is loaded. (Possibly similar to the way SQL injections are performed)
从简短的阅读来看,添加pickles
与安全性有关,因为它pickles
可以包含在加载某些内容时运行的任意 Python 代码。(可能类似于SQL注入的执行方式)
After updating np.load with the new param list, it's working for my project
使用新的参数列表更新 np.load 后,它适用于我的项目