我正在关注datacamp.com上的Tensorflow教程。 https://www.datacamp.com/community/tutorials/tensorflow-tutorial#gs.ljKz3uI
我陷入了代码的这一点,代码指的是使用 ndim 和尺寸的列表的打印尺寸和尺寸。我收到一个错误“列表对象没有属性ndim。”
`import os
import skimage
import pdb
from skimage import data
ROOT_PATH = "/tmp/"
train_data_directory =os.path.join(ROOT_PATH,
\mozilla_vijaya0/Training")
test_data_directory = os.path.join(ROOT_PATH,
"mozilla_vijaya0/Testing")
def load_data(data_directory):
directories = [d for d in os.listdir(data_directory)
if os.path.isdir(os.path.join(data_directory, d))]
labels = []
images = []
for d in directories:
label_directory = os.path.join(data_directory, d)
file_names = [os.path.join(label_directory, f)
for f in os.listdir(label_directory)
if f.endswith(".ppm")]
for f in file_names:
images.append(skimage.data.imread(f))
labels.append(int(d))
return images, labels
images, labels = load_data(train_data_directory)
print(images.ndim)
print(images.size)
images[0]`
显示列表的尺寸和大小的正确方法是什么。
答案 0 :(得分:3)
使用以下命令将图像转换为numpy数组
images = np.array(images)
现在你可以运行
了print(images.ndim)
print(images.size)