【发布时间】:2018-09-09 22:45:33
【问题描述】:
我正在尝试从this repo 运行代码,这意味着我必须使这个get_data 函数工作:
def get_data(self, pickle_path, aug_flag=True):
with open(pickle_path + self.image_filename, 'rb') as f:
images = pickle.load(f) # <--------- THIS line is the problem
images = np.array(images)
print('images: ', images.shape)
# do more things here
但它给了我错误ValueError: unsupported pickle protocol: 3
,所以我找到了建议here,他们推荐了不同的协议:pickle.dump(images, f, protocol=2)
def get_data(self, pickle_path, aug_flag=True):
with open(pickle_path + self.image_filename, 'rb') as f:
pickle.dump(images, f, protocol=2) # still bad
images = np.array(images)
print('images: ', images.shape)
# do more things here
但是,这给了我错误UnboundLocalError: local variable 'images' referenced before assignment。有没有办法解决这个问题,特别是StackGAN/misc/datasets.py?
【问题讨论】:
-
只做
other_images = np.array(images) -
您尝试遵循的建议是告诉您如何首先更改生成文件的代码,以便创建一个 Pickle 库实现的文件只支持protocol-2的可以加载。它并没有告诉您如何加载以错误格式创建的文件。
标签: python tensorflow