【问题标题】:StackGAN pickle errorStackGAN 泡菜错误
【发布时间】: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


【解决方案1】:

我找到了答案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 here

StackGAN 提供用 Python3 腌制的文件,我需要将它们转换为 Python2 协议

【讨论】:

  • 糟糕;这不起作用。一会儿看一下cmets的建议
猜你喜欢
  • 1970-01-01
  • 2016-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多