AttributeError: ‘NoneType’ object has no attribute ‘shape’ 原因与解决方法

今天一位朋友在用Python开发的roop一张图片视频换脸的时候,运行“python run.py"的时候结果报错如下:

AttributeError: 'NoneType' object has no attribute 'shape'

中文翻译

AttributeError:“NoneType”对象没有属性“shape”

 

AttributeError: 'NoneType' object has no attribute 'shape'

 

原因

通过上面的翻译大家也知道一个大概的原因了。主要原因如下:

1、图片不存在(路径不存在, 路径包含中文无法识别)。

2、读取的图片内容和默认读取时参数匹配不匹配。(默认读取的是3通道的彩色图)例如读取到的图片是灰度图,就会返回None。

3、也可能是路径中有中文。

 

我又要来了整个运行调试代码,如下:

(venv) E:\roop>python run.py
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
Qt: Untested Windows version 10.0 detected!
log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace).
log4cplus:ERROR Please initialize the log4cplus system properly.
[ WARN:0@260.427] global loadsave.cpp:248 cv::findDecoder imread_('C:/Users/鏉?download_path: C:\Users\杨/.insightface\models\buffalo_l
Downloading C:\Users\杨/.insightface\models\buffalo_l.zip from https://github.com/deepinsight/insightface/releases/download/v0.7/buffalo_l.zip...
100%|███████████████████████████████████████████████████████████████████████| 281857/281857 [00:10<00:00, 25674.22KB/s]
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\杨/.insightface\models\buffalo_l\1k3d68.onnx landmark_3d_68 ['None', 3, 192, 192] 0.0 1.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\杨/.insightface\models\buffalo_l\2d106det.onnx landmark_2d_106 ['None', 3, 192, 192] 0.0 1.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\杨/.insightface\models\buffalo_l\det_10g.onnx detection [1, 3, '?', '?'] 127.5 128.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\杨/.insightface\models\buffalo_l\genderage.onnx genderage ['None', 3, 96, 96] 0.0 1.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: C:\Users\杨/.insightface\models\buffalo_l\w600k_r50.onnx recognition ['None', 3, 112, 112] 127.5 127.5
set det-size: (640, 640)
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\杨\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "E:\roop\venv\lib\site-packages\customtkinter\windows\widgets\ctk_button.py", line 554, in _clicked
    self._command()
  File "E:\roop\roop\ui.py", line 103, in <lambda>
    start_button = ctk.CTkButton(root, text='Start', cursor='hand2', command=lambda: select_output_path(start))
  File "E:\roop\roop\ui.py", line 199, in select_output_path
    start()
  File "E:\roop\roop\core.py", line 137, in start
    if not frame_processor.pre_start():
  File "E:\roop\roop\processors\frame\face_swapper.py", line 45, in pre_start
    elif not get_one_face(cv2.imread(roop.globals.source_path)):
  File "E:\roop\roop\face_analyser.py", line 30, in get_one_face
    many_faces = get_many_faces(frame)
  File "E:\roop\roop\face_analyser.py", line 41, in get_many_faces
    return get_face_analyser().get(frame)
  File "E:\roop\venv\lib\site-packages\insightface\app\face_analysis.py", line 59, in get
    bboxes, kpss = self.det_model.detect(img,
  File "E:\roop\venv\lib\site-packages\insightface\model_zoo\retinaface.py", line 211, in detect
    im_ratio = float(img.shape[0]) / img.shape[1]
AttributeError: 'NoneType' object has no attribute 'shape'

 

解决方法

以我这为例子,由于我是用“roop”程序,它需要先上传一张图片和一个视频,我把图片和视频全都都放在 E:/roop/sucai/ 路径下,图片和视频也没有用中文,这就恢复正常了。

    A+
发布日期:2023年08月10日 11:55:49  所属分类:Python
最后更新时间:2023-08-10 11:55:49
标签:
付杰
  • ¥ 39.0元
  • 市场价:39.0元
  • ¥ 298.0元
  • 市场价:598.0元
  • ¥ 298.0元
  • 市场价:598.0元
  • ¥ 58元
  • 市场价:58元

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: