[Solved] AttributeError: ‘NoneType‘ object has no attribute ‘astype‘

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'


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: