AttributeError: 'NoneType' 对象没有属性 'reshape' 然后另一个错误没有属性 'values' 'resize'

问题描述

OG 代码

import os 
import cv2

calib_image_list = './pre_img/bounding_Boxes_25815.txt'
calib_batch_size = 10

def calib_input(iter):
    images = []
    line = open(calib_image_list).readlines()
    for index in range(0,calib_batch_size):
        curline = line[iter * calib_batch_size + index]
        calib_image_name = curline.strip()

        # open image as grayscale
        image = cv2.imread(calib_image_name,cv2.IMREAD_GRAYSCALE)

        # reshape
        image = image.reshape(28,28,1)

        # normalize
        image = image / 255.0

        images.append(image)
    return {"images_in": images}

我得到的错误是:AttributeError: 'nonetype' object has no attribute 'reshape'

然后,我搜索解决方案并修改为:

import os
import cv2
import numpy

calib_image_list = './pre_img/bounding_Boxes_25815.txt'
calib_batch_size = 10

def calib_input(iter):
    images = []
    line = open(calib_image_list).readlines()
    for index in range(0,cv2.IMREAD_GRAYSCALE)

        # reshape
        image = image.values.reshape(28,1)

        # normalize
        image = image / 255.0

        images.append(image)
    return {"images_in": images}

我得到的下一个错误:AttributeError: 'nonetype' object has no attribute 'values'

再一次,我修改为:

import os
import cv2
import numpy

calib_image_list = './pre_img/bounding_Boxes_25815.txt'
calib_batch_size = 10

def calib_input(iter):
    images = []
    line = open(calib_image_list).readlines()
    for index in range(0,cv2.IMREAD_GRAYSCALE)

        # reshape
        # image = image.reshape(28,1)
        image = image.resize(28,1)
        image = np.array(image)
        image = image.reshape(28,1)

        # normalize
        image = image / 255.0

        images.append(image)
    return {"images_in": images}

一个错误是:AttributeError: 'nonetype' 对象没有属性 'resize'

我该如何解决这个问题?

非常感谢您的帮助,谢谢。

顺便说一下,我在 Ubuntu 终端中运行这段代码,但我在 PyCharm 中修改代码

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)