MedicineToken / Medical-SAM2

Medical SAM 2: Segment Medical Images As Video Via Segment Anything Model 2
Apache License 2.0
455 stars 57 forks source link

RuntimeError: Could not infer dtype of numpy.int64 #66

Open sahikabetul opened 1 week ago

sahikabetul commented 1 week ago

Hello, thanks for great work!

I am trying to running the code with 3D data you provided, but I got this error. I set up Ubuntu Docker: Operating System: Ubuntu 22.04 (FROM ubuntu:22.04) Conda Version: 24.9.2 Python Version: 3.12.4 PyTorch: 2.4 CUDA: 12.1

It seems problem related to data. Do you have any recommendations?

Epoch 0:   0%|                                                                                                                                                                                    | 0/25 [00:04<?, ?img/s]
Traceback (most recent call last):
  File "/data/medicalSAM2/Medical-SAM2/train_3d.py", line 112, in <module>
    main()
  File "/data/medicalSAM2/Medical-SAM2/train_3d.py", line 95, in main
    loss, prompt_loss, non_prompt_loss = function.train_sam(args, net, optimizer1, optimizer2, nice_train_loader, epoch)
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/medicalSAM2/Medical-SAM2/func_3d/function.py", line 73, in train_sam
    for pack in train_loader:
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 701, in __next__
    data = self._next_data()
           ^^^^^^^^^^^^^^^^^
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 1465, in _next_data
    return self._process_data(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/dataloader.py", line 1491, in _process_data
    data.reraise()
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/_utils.py", line 715, in reraise
    raise exception
RuntimeError: Caught RuntimeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/_utils/worker.py", line 351, in _worker_loop
    data = fetcher.fetch(index)  # type: ignore[possibly-undefined]
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/_utils/fetch.py", line 55, in fetch
    return self.collate_fn(data)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/_utils/collate.py", line 398, in default_collate
    return collate(batch, collate_fn_map=default_collate_fn_map)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/_utils/collate.py", line 172, in collate
    key: collate(
         ^^^^^^^^
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/_utils/collate.py", line 172, in collate
    key: collate(
         ^^^^^^^^
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/_utils/collate.py", line 172, in collate
    key: collate(
         ^^^^^^^^
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/_utils/collate.py", line 155, in collate
    return collate_fn_map[elem_type](batch, collate_fn_map=collate_fn_map)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/miniconda/envs/medsam2/lib/python3.12/site-packages/torch/utils/data/_utils/collate.py", line 285, in collate_numpy_array_fn
    return collate([torch.as_tensor(b) for b in batch], collate_fn_map=collate_fn_map)
                    ^^^^^^^^^^^^^^^^^^
RuntimeError: Could not infer dtype of numpy.int64
sahikabetul commented 7 hours ago

And, when running 2D code with your provided dataset and weights, I don't face a problem like this. For your information