Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: some of the strides of a given numpy array are negative. This is currently not supported, but will be added in future releases. #27

Closed
PLPote opened this issue Mar 30, 2020 · 8 comments

Comments

@PLPote
Copy link

PLPote commented Mar 30, 2020

Hi,

I try to train a custom model on my machine and i get this error :
ValueError: some of the strides of a given numpy array are negative. This is currently not supported, but will be added in future releases.
I research a little bit and i saw that was an issue on Pytorch, but do you have any clue to fix that on detecto ??

My environment :
Windows
python 3.7
GPU: GeForce GTX 1050

nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 441.45       Driver Version: 441.45       CUDA Version: 10.2

Thank you

@alankbi
Copy link
Owner

alankbi commented Mar 31, 2020

Could you share the code you ran that led to this error?

@PLPote
Copy link
Author

PLPote commented Mar 31, 2020

The code is :

from detecto import core, utils, visualize

dataset=core.Dataset('images/')
model=core.Model(['character'])

model.fit(dataset)

@alankbi
Copy link
Owner

alankbi commented Mar 31, 2020

What's your torch and torchvision versions? If they're outdated then you may want to update them.

If that's not the issue, can you let me know what line of code is throwing the error? I can only speculate, but try providing custom transforms to core.Dataset in line with the solution presented here:

from torchvision import transforms

transform = transforms.Compose([
    transforms.Lambda(lambda img: img.copy()),
    transforms.ToTensor(), 
    utils.normalize_transform()
])

dataset=core.Dataset('images/', transform=transform)

@PLPote
Copy link
Author

PLPote commented Apr 1, 2020

torch : 1.4.0
torchvision : 0.5.0

Here it is the full error :

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-daffb2798a5f> in <module>
      2 model = core.Model(['character'])
      3 
----> 4 model.fit(dataset)

~\anaconda3\envs\pytor\lib\site-packages\detecto\core.py in fit(self, dataset, val_dataset, epochs, learning_rate, momentum, weight_decay, gamma, lr_step_size, verbose)
    467             # Training step
    468             self._model.train()
--> 469             for images, targets in dataset:
    470                 self._convert_to_int_labels(targets)
    471                 images, targets = self._to_device(images, targets)

~\anaconda3\envs\pytor\lib\site-packages\torch\utils\data\dataloader.py in __next__(self)
    343 
    344     def __next__(self):
--> 345         data = self._next_data()
    346         self._num_yielded += 1
    347         if self._dataset_kind == _DatasetKind.Iterable and \

~\anaconda3\envs\pytor\lib\site-packages\torch\utils\data\dataloader.py in _next_data(self)
    383     def _next_data(self):
    384         index = self._next_index()  # may raise StopIteration
--> 385         data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
    386         if self._pin_memory:
    387             data = _utils.pin_memory.pin_memory(data)

~\anaconda3\envs\pytor\lib\site-packages\torch\utils\data\_utils\fetch.py in fetch(self, possibly_batched_index)
     42     def fetch(self, possibly_batched_index):
     43         if self.auto_collation:
---> 44             data = [self.dataset[idx] for idx in possibly_batched_index]
     45         else:
     46             data = self.dataset[possibly_batched_index]

~\anaconda3\envs\pytor\lib\site-packages\torch\utils\data\_utils\fetch.py in <listcomp>(.0)
     42     def fetch(self, possibly_batched_index):
     43         if self.auto_collation:
---> 44             data = [self.dataset[idx] for idx in possibly_batched_index]
     45         else:
     46             data = self.dataset[possibly_batched_index]

~\anaconda3\envs\pytor\lib\site-packages\detecto\core.py in __getitem__(self, idx)
    196                         box[0, 0], box[0, 2] = box[0, (2, 0)]
    197                 else:
--> 198                     image = t(image)
    199 
    200             # Scale down box if necessary

~\anaconda3\envs\pytor\lib\site-packages\torchvision\transforms\transforms.py in __call__(self, pic)
     99             Tensor: Converted image.
    100         """
--> 101         return F.to_tensor(pic)
    102 
    103     def __repr__(self):

~\anaconda3\envs\pytor\lib\site-packages\torchvision\transforms\functional.py in to_tensor(pic)
     63             pic = pic[:, :, None]
     64 
---> 65         img = torch.from_numpy(pic.transpose((2, 0, 1)))
     66         # backward compatibility
     67         if isinstance(img, torch.ByteTensor):

ValueError: some of the strides of a given numpy array are negative. This is currently not supported, but will be added in future releases.

@alankbi
Copy link
Owner

alankbi commented Apr 1, 2020

Could you try the solution I posted above and see if that fixes the issue?

@PLPote
Copy link
Author

PLPote commented Apr 2, 2020

So i try your solution, first the program run for many hours and it didn't print anything. So i reinstall an environment and now i have this issue :

Traceback (most recent call last):
  File "test_detecto.py", line 14, in <module>
    model.fit(dataset)
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\detecto\core.py", line 469, in fit
    for images, targets in dataset:
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\torch\utils\data\dataloader.py", line 345, in __next__
    data = self._next_data()
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\torch\utils\data\dataloader.py", line 385, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\detecto\core.py", line 150, in __getitem__
    image = io.imread(img_name)
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\skimage\io\_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\skimage\io\manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\skimage\io\_plugins\imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\imageio\core\functions.py", line 267, in imread
    return reader.get_data(0)
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\imageio\core\format.py", line 346, in get_data
    im, meta = self._get_data(index, **kwargs)
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\imageio\plugins\pillow.py", line 301, in _get_data
    im, info = PillowFormat.Reader._get_data(self, index)
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\imageio\plugins\pillow.py", line 170, in _get_data
    i = self._im.tell()
  File "C:\Users\P-LPo\anaconda3\envs\pytorche\lib\site-packages\PIL\PngImagePlugin.py", line 827, in tell
    return self.__frame
AttributeError: 'PngImageFile' object has no attribute '_PngImageFile__frame'

@hugovk
Copy link

hugovk commented Apr 3, 2020

@PLPote That was a problem in Pillow 7.1.0, fixed in 7.1.1. Please could you upgrade and try again?

python-pillow/Pillow#4509

@alankbi
Copy link
Owner

alankbi commented May 29, 2020

Closing as this seems to be resolved.

@alankbi alankbi closed this as completed May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants