salesforce / LAVIS

LAVIS - A One-stop Library for Language-Vision Intelligence
BSD 3-Clause "New" or "Revised" License
9.78k stars 958 forks source link

TypeError: Cannot interpret 'torch.float32' as a data type #223

Closed onefish51 closed 1 year ago

onefish51 commented 1 year ago

when I tested examples/blip2_instructed_generation.ipynb a error occurred :

avg_gradcam = getAttMap(norm_img, gradcam[0][1], blur=True)
  File "/opt/conda/envs/oneformer/lib/python3.8/site-packages/lavis/common/gradcam.py", line 11, in getAttMap
    attMap = skimage_transform.resize(attMap, (img.shape[:2]), order=3, mode="constant")
  File "/opt/conda/envs/oneformer/lib/python3.8/site-packages/skimage/transform/_warps.py", line 154, in resize
    not (np.issubdtype(input_type, np.integer) and order == 0) and
  File "/opt/conda/envs/oneformer/lib/python3.8/site-packages/numpy/core/numerictypes.py", line 416, in issubdtype
    arg1 = dtype(arg1).type
TypeError: Cannot interpret 'torch.float32' as a data type
onefish51 commented 1 year ago

fixed it by:

gradcam_np = gradcam[0][1].numpy().astype(np.float32)
avg_gradcam = getAttMap(norm_img, gradcam_np, blur=True)
dxli94 commented 1 year ago

Seems to be a pytorch-related issue: https://github.com/pytorch/pytorch/issues/2246.

QinHsiu commented 1 year ago

try to transformer the data to numpy, works fine.

LKJ-np commented 1 year ago

通过以下方式修复它:

gradcam_np = gradcam[0][1].numpy().astype(np.float32)
avg_gradcam = getAttMap(norm_img, gradcam_np, blur=True)

projects/img2llm-vqa/img2llm_vqa.py resized_img = raw_image.resize((int(w scaling_factor), int(h scaling_factor))) norm_img = np.float32(resized_img) / 255 gradcam = samples['gradcams'].reshape(24,24)

avg_gradcam = getAttMap(norm_img, gradcam, blur=True) An error is also reported here, why? Connot interpret 'torch.float32' as a data type