【问题描述】

今天在运行github上的tiler项目时,使用自定义的图片和gen_circle_100文件夹运行代码时弹出错误'NoneType' object has no attribute 'shape'。

【问题解决】

Error定位在下面最后一句:

    img = cv2.imread(path, cv2.IMREAD_UNCHANGED)if img.shape[2] == 3:img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)

网上此问题的blog都是由于填写文件名错误导致的,与我的情况不同。

刚开始因为pycharm同时在cv2.imread处弹出 '__init__.py' 中找不到引用 'imread',而且定位到cv2的__init__.py也确实没有找到imread这个方法,让我误以为是我的cv2包导入错误或时cv2版本不兼容。

在多次尝试之后,恢复到初始的代码,重新运行,并在上述代码中间添加了两句输出当前img读取的文件名和类型的语句:

    img = cv2.imread(path, cv2.IMREAD_UNCHANGED)print(type(img))if img.shape[2] == 3:img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)

再次运行后结果如下:

Loading tiles0%|                                                                                  | 0/126 [00:00<?, ?it/s]<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>4%|██▉                                                                       | 5/126 [00:00<00:02, 47.43it/s]<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'numpy.ndarray'>
<class 'NoneType'>9%|██████▎                                                                  | 11/126 [00:00<00:02, 55.19it/s]

原来是在最开始读入tiles数据时误读了一个异常的文件引起的,打开文件夹查看了一圈没有发现奇怪的文件,又增加了一句,想看看是哪里来的害虫:

    print(path)img = cv2.imread(path, cv2.IMREAD_UNCHANGED)print(type(img))if img.shape[2] == 3:img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)

结果如下:

  0%|                                                                                  | 0/126 [00:00<?, ?it/s]/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_0.2_0.5_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_0.5_0.8_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_0.8_0.2_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_0.0_0.2_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_0.5_1.0_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_1.0_0.0_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_0.5_0.5_0.5_r0.png
<class 'numpy.ndarray'>6%|████                                                                      | 7/126 [00:00<00:01, 61.01it/s]/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_0.2_0.8_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_0.2_1.0_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_1.0_1.0_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/circle_100_0.5_0.0_0.5_r0.png
<class 'numpy.ndarray'>
/Users/kunliang/tiler/tiles/circles/gen_circle_100/.DS_Store
<class 'NoneType'>

原来是mac自动生成的.DS_Store文件。于是改变了运行的文件夹,使用gen_circle_200时成功运行。

原来是因为在Finder中打开文件夹后就会自动生成.DS_Store文件,且不能设置不让mac自动生成.DS_Store文件。

于是在bash中cd定位到gen_circle_100文件夹,输入ls -la查看果然有这个害虫,输入rm .DS_Store,在此查看ls -la已经删除了,然后再次运行我的程序,终于可以正常输出了。

猛男落泪,嘤嘤嘤~

‘NoneType‘ object has no attribute ‘shape‘相关推荐

  1. 成功解决AttributeError: ‘NoneType‘ object has no attribute ‘shape‘

    成功解决AttributeError: 'NoneType' object has no attribute 'shape' 目录 解决问题 解决思路 解决方法 解决问题 multiplier = [ ...

  2. 报错AttributeError: ‘NoneType‘ object has no attribute ‘shape‘

    环境: python3.6.4 opencv3.4.1.15 运行目标跟踪object_tracking文件夹中的mean函数时报错且不显示视频结果 Traceback (most recent ca ...

  3. AttributeError: ‘NoneType‘ object has no attribute ‘shape‘

    在运行训练文件时,出现了这样的问题:"AttributeError: 'NoneType' object has no attribute 'shape'". 后来参考了大神文章后 ...

  4. 报错分析:【AttributeError: ‘NoneType‘ object has no attribute ‘shape‘】

    -----------------------------------志当高远且脚踏实------------------------------------程_七辰 关于OpenCV读取图片报错 前 ...

  5. Traceback (most recent call last): File AttributeError: 'NoneType' object has no attribute 'group'

    Traceback (most recent call last):File "<stdin>", line 1, in <module> Attribut ...

  6. Keras问题“AttributeError: 'NoneType' object has no attribute 'update”解决

    BUG 在使用Keras训练模型时,在每个epoch完成后save_model时会报错 "AttributeError: 'NoneType' object has no attribute ...

  7. paddleocr ‘bytes‘ object has no attribute ‘shape‘

    paddleocr 训练reg时报错: paddleocr 'bytes' object has no attribute 'shape' [2022/02/08 21:15:54] root ERR ...

  8. pyspark AttributeError: 'NoneType' object has no attribute 'setCallSite'

    pyspark: AttributeError: 'NoneType' object has no attribute 'setCallSite' 我草,是pyspark的bug.解决方法: prin ...

  9. Pywinauto 应用后端类型选择错误:AttributeError: ‘NoneType‘ object has no attribute ‘backend‘. 原因及解决办法

    AttributeError: 'NoneType' object has no attribute 'backend'. 错误原因: 选择的应用后端类型不对. windows 上应用的后端类型有两种 ...

最新文章

  1. SyntaxError: Non-ASCII character ‘\xe4‘ in file xx(路径)
  2. 海思芯片对比选型_海思芯片的选型及特征参考说明大全
  3. eclipse如何设置js源文件编码
  4. Wampserver的安装与配置笔记
  5. springMvc配置文件
  6. 培训loadrunner感受
  7. TC中编辑程序快捷键
  8. x230无线网卡驱动服务器版,联想X230网卡驱动
  9. 浏览器的“心脏”——内核
  10. 围成一圈的排列组合问题_排列组合问题模拟练习题
  11. asp dotnet core 从零开始创建一个 WebApi 服务
  12. 硬盘分区怎么分?新手该如何操作?
  13. vivo6.0系统设备最完美激活xposed框架的教程
  14. 专用舆情监测服务公司,TOOM舆情监测公司排名全国
  15. python--剑指offer--14- I. 剪绳子
  16. Web前端工程师怎么样呢?薪资待遇如何呢?
  17. [:,None]和[None,:]
  18. Eclipse @override报错
  19. Arduino实验九——感光灯实验
  20. Lawliet|C语言学习笔记3——顺序结构

热门文章

  1. 漏刻有时地理信息可视化百度地图标注系统本地Excel版说明书
  2. mapbox js map监听on off 匹配问题
  3. GIS与BIM,倾斜摄影助力可视化设计更加真实
  4. HTML复习笔记<1>
  5. 程序无法卸载如何处理
  6. Microsoft Store无法打开解决方法
  7. 中国石油大学计算机科学与技术论文,中国石油大学(计算机科学与技术专业)毕业论文规范.doc...
  8. [转]关于Mysql设置等
  9. 掼蛋android程序,新版掼蛋下载_掼蛋新版安卓下载v7.0_玩游戏网
  10. 【产品经理】产品经理与需求管理