开发者社区> 问答> 正文

int()参数必须是字符串,类似字节的对象或数字,而不是'NoneType',如何解决此问题?

对于此代码,

import cv2
import numpy as np
from os import listdir
from os.path import isfile, join

data_path = 'dataset/'
onlyfiles = [f for f in listdir(data_path) if isfile(join(data_path,f))]

Training_Data, Labels = [], []

for i, files in enumerate(onlyfiles):
    image_path = data_path + onlyfiles[i]
    images = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
    Training_Data.append(np.asarray(images, dtype=np.uint8))
    Labels.append(i)

Labels = np.asarray(Labels, dtype=np.int32)

model = cv2.face.LBPHFaceRecognizer_create()

model.train(np.asarray(Training_Data), np.asarray(Labels))

print("Model Training Completed!!!!!")

我收到此错误

/usr/local/bin/python3.7 "/Users/mac/Google Drive/Read&Write2Database/knowledgeShelfPart-2.py"
Traceback (most recent call last):
  File "/Users/mac/Google Drive/Read&Write2Database/knowledgeShelfPart-2.py", line 14, in <module>
    Training_Data.append(np.asarray(images, dtype=np.uint8))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/numpy/core/numeric.py", line 492, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

问题来源:stackoverflow

展开
收起
is大龙 2020-03-23 20:18:25 806 0
1 条回答
写回答
取消 提交回答
  • 您可以将整个列表转换为整数。为了解决这个问题,您首先必须将列表转换为字符串,然后再将该字符串转换为整数。由于列表中有多个元素,因此python不知道要传递或转换列表中的哪个元素。

    回答来源:stackoverflow

    2020-03-23 20:18:29
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载