Problem description
When running the code, an error is reported attributeerror: 'nonetype' object has no attribute 'asttype'
, as shown in the following figure:
Traceback (most recent call last):
File "work/person_search-master/tools/demo.py", line 82, in <module>
query_feat = net.inference(query_img, query_roi).view(-1, 1)
File "/home/featurize/work/person_search-master/tools/../lib/models/network.py", line 178, in inference
processed_img, scale = img_preprocessing(img)
File "/home/featurize/work/person_search-master/tools/../lib/datasets/data_processing.py", line 49, in img_preprocessing
processed_img = img.astype(np.float32)
AttributeError: 'NoneType' object has no attribute 'astype'
Solution:
According to the error message, the error is reported because the img is a ‘NoneType’ object, so the ‘astype’ property cannot be used.
In general, the above error occurs when the img does not exist, so
- You need to make sure that the image exists in the appropriate path in the code.
- You need to run the command
python XXX.py
in the correct directory to ensure that XXX.py searches for the image in the correct directory.
Read More:
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [2021-10-05] Python Error: AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] pandas ExcelWrite AttributeError: ‘NoneType‘ object has no attribute ‘group‘
- [Solved] Paramiko error: AttributeError: ‘NoneType’ object has no attribute ‘time’
- [Solved] Failed to initialize GLFW AttributeError: ‘NoneType’ object has no attribute ‘point_size’
- [Solved] python Error: AttributeError: ‘NoneType‘ object has no attribute ‘split‘
- [Solved] AttributeError: ‘PngImageFile‘ object has no attribute ‘imshow‘
- [Solved] AttributeError: ‘DataParallel‘ object has no attribute ‘save‘
- Python 3.7 Error: AttributeError: ‘str‘ object has no attribute ‘decode‘ [How to Solve]
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘map‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘tolist‘
- [Solved] vpython: AttributeError: ‘box‘ object has no attribute ‘idx‘
- AttributeError: DatetimeProperties object has no attribute
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [Solved] AttributeError: ‘HTMLWriter‘ object has no attribute ‘_temp_names‘
- [Solved] AttributeError: DataFrame object has no attribute’xxx’
- [Solved] AttributeError WriteOnlyWorksheet object has no attribute cell
- [Solved] Pycharm error: attributeerror: ‘Htmlparser’ object has no attribute ‘unescape’
- [Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute