# RF-DETR ValueError: matrix contains invalid numeric entries

**URL:** <https://discuss.roboflow.com/t/rf-detr-valueerror-matrix-contains-invalid-numeric-entries/11605>\
**Category:** 🤝  Community Help\
**Tags:** segmentation, rf-detr\
**Created:** [December 15, 2025, 12:33pm UTC](https://discuss.roboflow.com/t/rf-detr-valueerror-matrix-contains-invalid-numeric-entries/11605 "2025-12-15T12:33:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabian](https://avatars.discourse-cdn.com/v4/letter/f/f6c823/32.png) [@Fabian](https://discuss.roboflow.com/u/Fabian)\
**Post date:** [December 15, 2025, 12:33pm UTC](https://discuss.roboflow.com/t/rf-detr-valueerror-matrix-contains-invalid-numeric-entries/11605/1 "2025-12-15T12:33:40Z")

</div>

_Hi there!_

Running the segmentation preview of RF-DETR seems to be causing a ValueError: matrix contains invalid numeric entries.

This is the error output:

* * *

ValueError Traceback (most recent call last)  
Cell In[5], line 1  
----\> 1 model.train(  
2 dataset\_dir=str(Path(full\_seg\_dataset\_name)),  
3 epochs=30,  
4 batch\_size=1,  
5 grad\_accum\_steps=4,  
6 lr=0.01,  
7 imgsz=960, # multiple of 24 for segmentation, multiple of 32\* for detection  
8 output\_dir=str(Path(“runs/full\_rfdetr”))  
9 )

File ~\AppData\Roaming\Python\Python313\site-packages\rfdetr\detr.py:83, in RFDETR.train(self, \*\*kwargs)  
79 “”"  
80 Train an RF-DETR model.  
81 “”"  
82 config = self.get\_train\_config(\*\*kwargs)  
—\> 83 self.train\_from\_config(config, \*\*kwargs)

File ~\AppData\Roaming\Python\Python313\site-packages\rfdetr\detr.py:191, in RFDETR.train\_from\_config(self, config, \*\*kwargs)  
182 early\_stopping\_callback = EarlyStoppingCallback(  
183 model=self.model,  
184 patience=config.early\_stopping\_patience,  
(…) 187 segmentation\_head=config.segmentation\_head  
188 )  
189 self.callbacks[“on\_fit\_epoch\_end”].append(early\_stopping\_callback.update)  
→ 191 self.model.train(  
192 \*\*all\_kwargs,  
193 callbacks=self.callbacks,  
194 )

File ~\AppData\Roaming\Python\Python313\site-packages\rfdetr\main.py:341, in Model.train(self, callbacks, \*\*kwargs)  
339 model.train()  
340 criterion.train()  
→ 341 train\_stats = train\_one\_epoch(  
342 model, criterion, lr\_scheduler, data\_loader\_train, optimizer, device, epoch,  
343 effective\_batch\_size, args.clip\_max\_norm, ema\_m=self.ema\_m, schedules=schedules,  
344 num\_training\_steps\_per\_epoch=num\_training\_steps\_per\_epoch,  
345 vit\_encoder\_num\_layers=args.vit\_encoder\_num\_layers, args=args, callbacks=callbacks)  
346 train\_epoch\_time = time.time() - epoch\_start\_time  
347 train\_epoch\_time\_str = str(datetime.timedelta(seconds=int(train\_epoch\_time)))

File ~\AppData\Roaming\Python\Python313\site-packages\rfdetr\engine.py:130, in train\_one\_epoch(model, criterion, lr\_scheduler, data\_loader, optimizer, device, epoch, batch\_size, max\_norm, ema\_m, schedules, num\_training\_steps\_per\_epoch, vit\_encoder\_num\_layers, args, callbacks)  
128 with autocast(\*\*get\_autocast\_args(args)):  
129 outputs = model(new\_samples, new\_targets)  
→ 130 loss\_dict = criterion(outputs, new\_targets)  
131 weight\_dict = criterion.weight\_dict  
132 losses = sum(  
133 (1 / args.grad\_accum\_steps) \* loss\_dict[k] \* weight\_dict[k]  
134 for k in loss\_dict.keys()  
135 if k in weight\_dict  
136 )

File ~\AppData\Roaming\Python\Python313\site-packages\torch\nn\modules\module.py:1751, in Module.\_wrapped\_call\_impl(self, \*args, \*\*kwargs)  
1749 return self.\_compiled\_call\_impl(\*args, \*\*kwargs) # type: ignore[misc]  
1750 else:  
→ 1751 return self.\_call\_impl(\*args, \*\*kwargs)

File ~\AppData\Roaming\Python\Python313\site-packages\torch\nn\modules\module.py:1762, in Module.\_call\_impl(self, \*args, \*\*kwargs)  
1757 # If we don’t have any hooks, we want to skip the rest of the logic in  
1758 # this function, and just call forward.  
1759 if not (self.\_backward\_hooks or self.\_backward\_pre\_hooks or self.\_forward\_hooks or self.\_forward\_pre\_hooks  
1760 or \_global\_backward\_pre\_hooks or \_global\_backward\_hooks  
1761 or \_global\_forward\_hooks or \_global\_forward\_pre\_hooks):  
→ 1762 return forward\_call(\*args, \*\*kwargs)  
1764 result = None  
1765 called\_always\_called\_hooks = set()

File ~\AppData\Roaming\Python\Python313\site-packages\rfdetr\models\lwdetr.py:537, in SetCriterion.forward(self, outputs, targets)  
534 outputs\_without\_aux = {k: v for k, v in outputs.items() if k != ‘aux\_outputs’}  
536 # Retrieve the matching between the outputs of the last layer and the targets  
→ 537 indices = self.matcher(outputs\_without\_aux, targets, group\_detr=group\_detr)  
539 # Compute the average number of target boxes accross all nodes, for normalization purposes  
540 num\_boxes = sum(len(t[“labels”]) for t in targets)

File ~\AppData\Roaming\Python\Python313\site-packages\torch\nn\modules\module.py:1751, in Module.\_wrapped\_call\_impl(self, \*args, \*\*kwargs)  
1749 return self.\_compiled\_call\_impl(\*args, \*\*kwargs) # type: ignore[misc]  
1750 else:  
→ 1751 return self.\_call\_impl(\*args, \*\*kwargs)

File ~\AppData\Roaming\Python\Python313\site-packages\torch\nn\modules\module.py:1762, in Module.\_call\_impl(self, \*args, \*\*kwargs)  
1757 # If we don’t have any hooks, we want to skip the rest of the logic in  
1758 # this function, and just call forward.  
1759 if not (self.\_backward\_hooks or self.\_backward\_pre\_hooks or self.\_forward\_hooks or self.\_forward\_pre\_hooks  
1760 or \_global\_backward\_pre\_hooks or \_global\_backward\_hooks  
1761 or \_global\_forward\_hooks or \_global\_forward\_pre\_hooks):  
→ 1762 return forward\_call(\*args, \*\*kwargs)  
1764 result = None  
1765 called\_always\_called\_hooks = set()

File ~\AppData\Roaming\Python\Python313\site-packages\torch\utils\_contextlib.py:116, in context\_decorator..decorate\_context(\*args, \*\*kwargs)  
113 @functools.wraps(func)  
114 def decorate\_context(\*args, \*\*kwargs):  
115 with ctx\_factory():  
→ 116 return func(\*args, \*\*kwargs)

File ~\AppData\Roaming\Python\Python313\site-packages\rfdetr\models\matcher.py:152, in HungarianMatcher.forward(self, outputs, targets, group\_detr)  
150 for g\_i in range(group\_detr):  
151 C\_g = C\_list[g\_i]  
→ 152 indices\_g = [linear\_sum\_assignment(c[i]) for i, c in enumerate(C\_g.split(sizes, -1))]  
153 if g\_i == 0:  
154 indices = indices\_g

ValueError: matrix contains invalid numeric entries

The training run crashes anywhere between epoch 2 to 20. I am also adding a screenshot of the terminal output to visualize where that happens:

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/2X/b/b22692d082757f156f1cbc02fcf6d114958bb24d.png)

To fix this I have tried to do the following:

- Lower batch sizes from 16 → 8 → and now I’m at 4
- Generated a script that pinpoints images in the dataset that might be formatted in a wrong way. From the original 1500 images in my dataset I am now down to 1250 since their bounding boxes seemed to be out of bounds. (Which is weird because this dataset is downloaded straight from the Roboflow application, the COCO segmentation annotation format.)
- To get a better view of where the problem lies I also trained a RFDETRNano() instead of the RFDETRSegPreview() using the same dataset but in COCO annotation format (not COCO segmentation annotation format) directly downloaded from the Roboflow application. And this worked perfectly fine.

Hope y’all can help me out, thanks for reading ! 🙂

- **Project Type: Segmentation**
- **Operating System & Browser: Windows**
- **Project Universe Link or Workspace/Project ID:** aiprojectretrofiteurope/rooftops-all-ugayi

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/bb6edbfa56d0cf2ee603f061e9e09103502cc8cc.png) [@system](https://discuss.roboflow.com/u/system)\
**Post date:** [January 5, 2026, 12:34pm UTC](https://discuss.roboflow.com/t/rf-detr-valueerror-matrix-contains-invalid-numeric-entries/11605/2 "2026-01-05T12:34:22Z")

</div>

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
