我正在尝试运行this代码库中的代码,这意味着我必须让这个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?
发布于 2018-03-31 06:40:51
我找到了答案here
def get_data(self, pickle_path, aug_flag=True):
with open(pickle_path + self.image_filename, 'rb') as f:
pickle.dump(pickle.load(sys.stdin), sys.stdout, 2) # <----- *****
images = np.array(images)
print('images: ', images.shape)
# do more things hereStackGAN提供了在Python3中保存的文件,我需要将这些文件转换为Python2协议
https://stackoverflow.com/questions/49582103
复制相似问题