Skip to content

Commit 3b5cbcf

Browse files
committed
fix predict oom and add some comments
1 parent 2d22a7c commit 3b5cbcf

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

rtdetr_paddle/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ path/to/custom/data/
108108

109109
3. Modify model config [`pretrain_weights`](configs/rtdetr/_base_/rtdetr_r50vd.yml) to coco pretrained parameters url in model zoo.
110110

111+
```bash
112+
# or modified in command line
113+
114+
fleetrun --gpus=0,1,2,3 tools/train.py -c configs/rtdetr/rtdetr_r50vd_6x_coco.yml -o pretrain_weights=https://bj.bcebos.com/v1/paddledet/models/rtdetr_r50vd_6x_coco.pdparams --eval
115+
```
111116
</details>
112117

113118

@@ -171,10 +176,11 @@ trtexec --onnx=./rtdetr_r50vd_6x_coco.onnx \
171176
<details>
172177
<summary>1. Parameters and FLOPs </summary>
173178

174-
1. Find and modify [paddle flops source code](https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/hapi/dynamic_flops.py#L28)
179+
1. Find and modify paddle [`dynamic_flops.py` ](https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/hapi/dynamic_flops.py#L28) source code in your local machine
175180

176181
```python
177-
# anaconda3/lib/python3.8/site-packages/paddle/hapi/dynamic_flops.py
182+
# eg. /path/to/anaconda3/lib/python3.8/site-packages/paddle/hapi/dynamic_flops.py
183+
178184
def flops(net, input_size, inputs=None, custom_ops=None, print_detail=False):
179185
if isinstance(net, nn.Layer):
180186
# If net is a dy2stat model, net.forward is StaticFunction instance,

rtdetr_paddle/configs/rtdetr/_base_/rtdetr_r50vd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ema_decay_type: "exponential"
77
ema_filter_no_grad: True
88
hidden_dim: 256
99
use_focal_loss: True
10-
eval_size: [640, 640]
10+
eval_size: [640, 640] # h, w
1111

1212

1313
DETR:

rtdetr_paddle/configs/rtdetr/_base_/rtdetr_reader.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ TrainReader:
2222
EvalReader:
2323
sample_transforms:
2424
- Decode: {}
25-
- Resize: {target_size: [640, 640], keep_ratio: False, interp: 2}
25+
- Resize: {target_size: [640, 640], keep_ratio: False, interp: 2} # target_size: (h, w)
2626
- NormalizeImage: {mean: [0., 0., 0.], std: [1., 1., 1.], norm_type: none}
2727
- Permute: {}
2828
batch_size: 4

rtdetr_paddle/ppdet/engine/trainer.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ def setup_metrics_for_loader():
650650
for step_id, data in enumerate(tqdm(loader)):
651651
self.status['step_id'] = step_id
652652
# forward
653-
outs = self.model(data)
653+
with paddle.no_grad():
654+
outs = self.model(data)
654655

655656
outs['bbox'] = outs['bbox'].numpy() # only in test mode
656657
shift_amount = data['st_pix']
@@ -798,10 +799,12 @@ def setup_metrics_for_loader():
798799
for step_id, data in enumerate(tqdm(loader)):
799800
self.status['step_id'] = step_id
800801
# forward
801-
if hasattr(self.model, 'modelTeacher'):
802-
outs = self.model.modelTeacher(data)
803-
else:
804-
outs = self.model(data)
802+
with paddle.no_grad():
803+
if hasattr(self.model, 'modelTeacher'):
804+
outs = self.model.modelTeacher(data)
805+
else:
806+
outs = self.model(data)
807+
805808
for _m in metrics:
806809
_m.update(data, outs)
807810

rtdetr_paddle/ppdet/utils/visualizer.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,8 @@ def draw_bbox(image, im_id, catid2name, bboxes, threshold):
127127
# draw label
128128
text = "{} {:.2f}".format(catid2name[catid], score)
129129
# tw, th = draw.textsize(text)
130-
131-
if int(PIL.__version__.split('.')[0]) < 10:
132-
tw, th = draw.textsize(text)
133-
else:
134-
left, top, right, bottom = draw.textbbox((0, 0), text)
135-
tw, th = right - left, bottom - top
130+
left, top, right, bottom = draw.textbbox((0, 0), text)
131+
tw, th = right - left, bottom - top
136132

137133
draw.rectangle(
138134
[(xmin + 1, ymin - th), (xmin + tw + 1, ymin)], fill=color)

0 commit comments

Comments
 (0)