Tensorflow'NoneType'对象没有属性'shape'

时间:2019-12-02 09:38:45

标签: python tensorflow operating-system cv2

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
import os
import cv2
from tqdm import tqdm

DATADIR ="C:/Users/Park/Project/TrainingData"
CATEGORIES = ["doll", "machine", "puzzle"]

for category in CATEGORIES:
    path = os.path.join(DATADIR, category)
    for img in os.listdir(path):
        img_array = cv2.imread(os.path.join(path, img), cv2.IMREAD_COLOR)
        print(" Image shape : ", img_array.shape)
        plt.imshow(img_array)
        plt.show()

每个文件夹包含50个jpg格式的图像文件。输出到第二个“ machine”文件夹,而“ puzzle”文件夹不输出到第三个文件夹。如果更改文件夹名称的顺序,则无论图像数量如何,都会显示图片。当我尝试输出第三个文件夹时,出现一个“ NoneType”对象没有属性“ shape”错误。

1 个答案:

答案 0 :(得分:0)

要快速发现问题,请添加

if img_array is None:
    print("imread failed on {}".format(img))