嗨,我有一个包含图像的泡菜文件。我正在尝试加载它并执行操作,但出现错误:
AttributeError Traceback (most recent call last)
<ipython-input-51-58c2e02a7a5a> in <module>
21 return (x_train, y_train), (x_test, y_test)
22
---> 23 load_data('C:/siamfc_ardiya/data/images.pck')
<ipython-input-51-58c2e02a7a5a> in load_data(path)
16 """
17 #path = "C:/siamfc_ardiya/data/images.pck"
---> 18 with np.load(path, allow_pickle=True) as f:
19 x_train, y_train = f['x_train'], f['y_train']
20 x_test, y_test = f['x_test'], f['y_test']
AttributeError: __enter__
我的代码如下:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
def load_data(path):
"""Loads the images from pickle file.
# Arguments
path: path where the pickle file is located
# Returns
Tuple of Numpy arrays: `(x_train, y_train), (x_test, y_test)`.
"""
#path = "C:/siamfc_ardiya/data/images.pck"
with np.load(path, allow_pickle=True) as f:
x_train, y_train = f['x_train'], f['y_train']
x_test, y_test = f['x_test'], f['y_test']
return (x_train, y_train), (x_test, y_test)
load_data('C:/siamfc_ardiya/data/images.pck')
因此,在最后一行中,它应该加载pickle文件并返回Numpy数组的元组。但是相反,我得到了错误。有什么想法我做错了什么以及如何使此代码起作用?