Bug in pytorch with yolact

Sylvain_Ard: <p>Hello !</p>
<p>I have this bug :</p>
<pre><code class="lang-auto">runfile('C:/Users/Sylvain ARD/Dropbox/Documents Sylvain/travail avec Boubacar/yolact/yolact-master/yolact-master/train.py', wdir='C:/Users/Sylvain ARD/Dropbox/Documents Sylvain/travail avec Boubacar/yolact/yolact-master/yolact-master')
loading annotations into memory...
Done (t=0.05s)
creating index...
index created!
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
Initializing weights...
Begin training!

epoch :  0
Traceback (most recent call last):

  File "C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\train.py", line 505, in &lt;module&gt;
    train()

  File "C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\train.py", line 271, in train
    for datum in data_loader:

  File "C:\Users\Sylvain ARD\.conda\envs\yolact\lib\site-packages\torch\utils\data\dataloader.py", line 819, in __next__
    return self._process_data(data)

  File "C:\Users\Sylvain ARD\.conda\envs\yolact\lib\site-packages\torch\utils\data\dataloader.py", line 846, in _process_data
    data.reraise()

  File "C:\Users\Sylvain ARD\.conda\envs\yolact\lib\site-packages\torch\_utils.py", line 369, in reraise
    raise self.exc_type(msg)

TypeError: __init__() missing 4 required positional arguments: 'casting', 'from_', 'to', and 'i'

</code></pre>
<p>please help me !<br>
Best regards</p>

albanD: <p>Hi,</p>
<p>It would be very helpful if you shared some information about what you’re doing when this happened?<br>
When debugging issues happening in the dataloading, I would recommend setting the number of workers to 0 as well to get more helpful stack traces.</p>

Sylvain_Ard: <p>It happened when I run train.py<br>
what do you call workers ?</p>

albanD: <aside class="quote no-group" data-username="Sylvain_Ard" data-post="3" data-topic="110573">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/sylvain_ard/48/30714_2.png" class="avatar"> Sylvain_Ard:</div>
<blockquote>
<p>It happened when I run train.py</p>
</blockquote>
</aside>
<p>I don’t think we have any file called train.py in pytorch?</p>
<blockquote>
<p>what do you call workers ?</p>
</blockquote>
<p>The error comes from the <a href="https://pytorch.org/docs/stable/data.html?highlight=dataloader#torch.utils.data.DataLoader">dataloader</a> workers.</p>

Sylvain_Ard: <p>Hi !<br>
I use the yolact code :</p><aside class="onebox githubfolder">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="16" height="16">
      <a href="https://github.com/dbolya/yolact" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars.githubusercontent.com/u/19721752?s=400&amp;amp;v=4" class="thumbnail onebox-full-image" width="60" height="60">

<h3><a href="https://github.com/dbolya/yolact" target="_blank" rel="noopener nofollow ugc">dbolya/yolact</a></h3>


  <p><span class="label1">A simple, fully convolutional model for real-time instance segmentation.</span></p>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<p>
how to use 0 workers please ?<br>
Thank you</p>

Sylvain_Ard: <p>when I do 0 worker I get :</p>
<pre><code class="lang-auto">runfile('C:/Users/Sylvain ARD/Dropbox/Documents Sylvain/travail avec Boubacar/yolact/yolact-master/yolact-master/train.py', wdir='C:/Users/Sylvain ARD/Dropbox/Documents Sylvain/travail avec Boubacar/yolact/yolact-master/yolact-master')
Reloaded modules: data, data.config, backbone, data.coco, utils, utils.augmentations, utils.functions, layers, layers.functions, layers.functions.detection, layers.box_utils, utils.timer, layers.modules, layers.modules.multibox_loss, layers.interpolate, utils.logger, utils.nvinfo, yolact, eval, layers.output_utils
Scaling parameters by 0.12 to account for a batch size of 1.
Per-GPU batch size is less than the recommended limit for batch norm. Disabling batch norm.
loading annotations into memory...
Done (t=0.03s)
creating index...
index created!
loading annotations into memory...
Done (t=0.00s)
creating index...
index created!
Initializing weights...
Begin training!

epoch :  0
C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\utils\augmentations.py:309: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  mode = random.choice(self.sample_options)
Traceback (most recent call last):

  File "C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\train.py", line 505, in &lt;module&gt;
    train()

  File "C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\train.py", line 271, in train
    for datum in data_loader:

  File "C:\Users\Sylvain ARD\.conda\envs\yolact\lib\site-packages\torch\utils\data\dataloader.py", line 346, in __next__
    data = self.dataset_fetcher.fetch(index)  # may raise StopIteration

  File "C:\Users\Sylvain ARD\.conda\envs\yolact\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\Sylvain ARD\.conda\envs\yolact\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in &lt;listcomp&gt;
    data = [self.dataset[idx] for idx in possibly_batched_index]

  File "C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\data\coco.py", line 94, in __getitem__
    im, gt, masks, h, w, num_crowds = self.pull_item(index)

  File "C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\data\coco.py", line 168, in pull_item
    {'num_crowds': 0, 'labels': np.array([0])})

  File "C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\utils\augmentations.py", line 688, in __call__
    return self.augment(img, masks, boxes, labels)

  File "C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\utils\augmentations.py", line 55, in __call__
    img, masks, boxes, labels = t(img, masks, boxes, labels)

  File "C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\utils\augmentations.py", line 167, in __call__
    boxes[:, [0, 2]] *= (width  / img_w)

UFuncTypeError: Cannot cast ufunc 'multiply' output from dtype('float64') to dtype('int32') with casting rule 'same_kind'


C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\utils\augmentations.py:309: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  mode = random.choice(self.sample_options)
C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\utils\augmentations.py:309: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  mode = random.choice(self.sample_options)
C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\utils\augmentations.py:309: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  mode = random.choice(self.sample_options)
C:\Users\Sylvain ARD\Dropbox\Documents Sylvain\travail avec Boubacar\yolact\yolact-master\yolact-master\utils\augmentations.py:309: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
  mode = random.choice(self.sample_options)
</code></pre>

Sylvain_Ard: <p>I corrected the bug it was a bug in my annotation json</p>

albanD: <p>Congrats on finding it!</p>

dimimal: <p>I have a similar issue. Can you tell me what the bug was in your json annotation?</p>

Sylvain_Ard: <p>here are my annotations files :</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <img src="https://cfl.dropboxstatic.com/static/images/favicon-vflUeLeeY.ico" class="site-icon" width="16" height="16">
      <a href="https://www.dropbox.com/sh/ezmtwn6x5kn8dgj/AABr5f6aL-bs5evIX_KvjgWga?dl=0" target="_blank" rel="noopener nofollow ugc">Dropbox</a>
  </header>
  <article class="onebox-body">
    <img src="https://www.dropbox.com/static/images/spectrum-icons/generated/content/content-folder_dropbox-large.png" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://www.dropbox.com/sh/ezmtwn6x5kn8dgj/AABr5f6aL-bs5evIX_KvjgWga?dl=0" target="_blank" rel="noopener nofollow ugc">annotations</a></h3>

<p>Shared with Dropbox</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<p>
so you can compare with yours</p>

Sylvain_Ard: <p>I remember only two errors : the polygons must be an array of polygons and not a simple polygon and there was instances IDs duplicated</p>

Sylvain_Ard: <p>is that has helped you ?</p>

Sylvain_Ard: <p>in addition I added :</p>
<pre><code class="lang-auto">boxes=boxes.astype("float64")####Ajouté par Sylvain Ard
</code></pre>
<p>at line 168 of augmentations.py</p>