TransWikia.com

numpy array type not supported?

Stack Overflow Asked by user3066560 on December 30, 2021

I’m trying to copy a model I was able to follow and run through a tutorial, but this time with my own data.

I was able to convert my own MRI images to numpy arrays in the same dimensions as the arrays the tutorial data is.

I tried replacing the numpy arrays in my tutorial with my own arrays and writing my own fictional csv file for normal or abnormal (case, not case).

However when I run it, I get:

(Pytorch) C:UsersGlaDOSPythonProjectsdicomnpy>python train.py  -t acl -p sagittal --epochs=10 --prefix_name hue
Traceback (most recent call last):
  File "train.py", line 277, in <module>
    run(args)
  File "train.py", line 214, in run
    mrnet, train_loader, epoch, num_epochs, optimizer, writer, current_lr, log_every)
  File "train.py", line 34, in train_model
    for i, (image, label, weight) in enumerate(train_loader):
  File "C:UsersGlaDOSanaconda3envsPytorchlibsite-packagestorchutilsdatadataloader.py", line 345, in __next__
    data = self._next_data()
  File "C:UsersGlaDOSanaconda3envsPytorchlibsite-packagestorchutilsdatadataloader.py", line 385, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "C:UsersGlaDOSanaconda3envsPytorchlibsite-packagestorchutilsdata_utilsfetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:UsersGlaDOSanaconda3envsPytorchlibsite-packagestorchutilsdata_utilsfetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:UsersGlaDOSPythonProjectsdicomnpydataloader.py", line 56, in __getitem__
    array = self.transform(array)
  File "c:usersgladossrctorchsampletorchsampletransformstensor_transforms.py", line 32, in __call__
    inputs = transform(*inputs)
  File "C:UsersGlaDOSanaconda3envsPytorchlibsite-packagestorchvisiontransformstransforms.py", line 313, in __call__
    return self.lambd(img)
  File "train.py", line 167, in <lambda>
    transforms.Lambda(lambda x: torch.Tensor(x)),
TypeError: can't convert np.ndarray of type numpy.uint16. The only supported types are: float64, float32, float16, int64, int32, int16, int8, uint8, and bool.

Now I’m wondering if this error means I somehow didn’t convert my MRI’s to the "correct" numpy array type? And if so, how do I go about changing them to the correct type?

One Answer

You can redefining the variable with astype

your_array = your_array.astype(np.uint16)

Answered by Philip Purwoko on December 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP