我编写了以下代码,将图像转换为numpy数组。但是我得到了错误('模块'对象没有属性'字节')。解决办法是什么? (Numpy版本:1.15.2,scikit映像版本:0.14.1)谢谢...
import os
import numpy as np
from PIL import Image
import glob
from skimage.io import imread
def load_train(train_path):
images = []
labels = []
classes = os.listdir(train_path)
num_classes = 6
for cls in classes:
index = classes.index(cls)
path = os.path.join(train_path, cls, '*jpg')
files = glob.glob(path)
for fl in files:
image = imread(fl,mode='RGB')
image = image.astype(np.float32)
image = np.multiply(image, 1.0 / 255.0)
label = np.zeros(num_classes)
if image.shape == (32,32,3):
images.append(image)
label[index] = 1.0
labels.append(label)
images = np.array(images)
labels = np.array(labels)
np.save('image.npy',images)
np.save('label.npy',labels)
return images.shape,labels.shape
if __name__ == '__main__':
result = load_train()
print(result)
错误消息:
Traceback (most recent call last):
File "numpy.py", line 2, in <module>
import numpy as np
File "/truba/home/atkorez/numpy.py", line 5, in <module>
from skimage.io import imread
File "/truba/home/atkorez/.local/lib/python2.7/site-packages/skimage/__init__.py", line 167, in <module>
from .util.dtype import (img_as_float32,
File "/truba/home/atkorez/.local/lib/python2.7/site-packages/skimage/util/__init__.py", line 1, in <module>
from .dtype import (img_as_float32, img_as_float64, img_as_float,
File "/truba/home/atkorez/.local/lib/python2.7/site-packages/skimage/util/dtype.py", line 19, in <module>
_integer_types = (np.byte, np.ubyte, # 8 bits
AttributeError: 'module' object has no attribute 'byte'