Skip to content

Commit f42f843

Browse files
authored
Merge pull request #2280 from Trusted-AI/dev_1.15.2
Update to ART 1.15.2
2 parents 74edff7 + ef3bb2d commit f42f843

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

art/estimators/object_detection/pytorch_faster_rcnn.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838

3939
class PyTorchFasterRCNN(PyTorchObjectDetector):
4040
"""
41-
This class implements a model-specific object detector using Faster-RCNN and PyTorch following the input and output
41+
This class implements a model-specific object detector using Faster R-CNN and PyTorch following the input and output
4242
formats of torchvision.
4343
"""
4444

4545
def __init__(
4646
self,
47-
model: Optional["torchvision.models.detection.fasterrcnn_resnet50_fpn"] = None,
47+
model: Optional["torchvision.models.detection.FasterRCNN"] = None,
4848
input_shape: Tuple[int, ...] = (-1, -1, -1),
4949
optimizer: Optional["torch.optim.Optimizer"] = None,
5050
clip_values: Optional["CLIP_VALUES_TYPE"] = None,
51-
channels_first: Optional[bool] = False,
51+
channels_first: Optional[bool] = True,
5252
preprocessing_defences: Union["Preprocessor", List["Preprocessor"], None] = None,
5353
postprocessing_defences: Union["Postprocessor", List["Postprocessor"], None] = None,
5454
preprocessing: "PREPROCESSING_TYPE" = None,
@@ -63,13 +63,13 @@ def __init__(
6363
"""
6464
Initialization.
6565
66-
:param model: Faster-RCNN model. The output of the model is `List[Dict[Tensor]]`, one for each input image. The
67-
fields of the Dict are as follows:
66+
:param model: Faster R-CNN model. The output of the model is `List[Dict[str, torch.Tensor]]`, one for
67+
each input image. The fields of the Dict are as follows:
6868
69-
- boxes (FloatTensor[N, 4]): the predicted boxes in [x1, y1, x2, y2] format, with values \
70-
between 0 and H and 0 and W
71-
- labels (Int64Tensor[N]): the predicted labels for each image
72-
- scores (Tensor[N]): the scores or each prediction
69+
- boxes [N, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and
70+
0 <= y1 < y2 <= H.
71+
- labels [N]: the labels for each image.
72+
- scores [N]: the scores of each prediction.
7373
:param input_shape: The shape of one input sample.
7474
:param optimizer: The optimizer for training the classifier.
7575
:param clip_values: Tuple of the form `(min, max)` of floats or `np.ndarray` representing the minimum and

art/estimators/object_detection/pytorch_object_detector.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(
5252
input_shape: Tuple[int, ...] = (-1, -1, -1),
5353
optimizer: Optional["torch.optim.Optimizer"] = None,
5454
clip_values: Optional["CLIP_VALUES_TYPE"] = None,
55-
channels_first: Optional[bool] = False,
55+
channels_first: Optional[bool] = True,
5656
preprocessing_defences: Union["Preprocessor", List["Preprocessor"], None] = None,
5757
postprocessing_defences: Union["Postprocessor", List["Postprocessor"], None] = None,
5858
preprocessing: "PREPROCESSING_TYPE" = None,
@@ -67,13 +67,13 @@ def __init__(
6767
"""
6868
Initialization.
6969
70-
:param model: Object detection model. The output of the model is `List[Dict[Tensor]]`, one for each input
71-
image. The fields of the Dict are as follows:
70+
:param model: Object detection model. The output of the model is `List[Dict[str, torch.Tensor]]`, one for
71+
each input image. The fields of the Dict are as follows:
7272
73-
- boxes (FloatTensor[N, 4]): the predicted boxes in [x1, y1, x2, y2] format, with values
74-
between 0 and H and 0 and W
75-
- labels (Int64Tensor[N]): the predicted labels for each image
76-
- scores (Tensor[N]): the scores or each prediction
73+
- boxes [N, 4]: the boxes in [x1, y1, x2, y2] format, with 0 <= x1 < x2 <= W and
74+
0 <= y1 < y2 <= H.
75+
- labels [N]: the labels for each image.
76+
- scores [N]: the scores of each prediction.
7777
:param input_shape: The shape of one input sample.
7878
:param optimizer: The optimizer for training the classifier.
7979
:param clip_values: Tuple of the form `(min, max)` of floats or `np.ndarray` representing the minimum and
@@ -215,7 +215,7 @@ def _preprocess_and_convert_inputs(
215215

216216
if not self.channels_first:
217217
x_tensor = torch.permute(x_tensor, (0, 3, 1, 2))
218-
x_tensor /= norm_factor
218+
x_tensor = x_tensor / norm_factor
219219

220220
# Set gradients
221221
if not no_grad:
@@ -236,7 +236,7 @@ def _preprocess_and_convert_inputs(
236236

237237
if not self.channels_first:
238238
x_preprocessed = torch.permute(x_preprocessed, (0, 3, 1, 2))
239-
x_preprocessed /= norm_factor
239+
x_preprocessed = x_preprocessed / norm_factor
240240

241241
# Set gradients
242242
if not no_grad:

art/estimators/object_detection/pytorch_yolo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def translate_labels_x1y1x2y2_to_xcycwh(
103103
labels[:, 2:6] = label_dict["boxes"]
104104

105105
# normalize bounding boxes to [0, 1]
106-
labels[:, 2:6:2] /= width
107-
labels[:, 3:6:2] /= height
106+
labels[:, 2:6:2] = labels[:, 2:6:2] / width
107+
labels[:, 3:6:2] = labels[:, 3:6:2] / height
108108

109109
# convert from x1y1x2y2 to xcycwh
110110
labels[:, 4] -= labels[:, 2]
@@ -148,7 +148,7 @@ def __init__(
148148
"""
149149
Initialization.
150150
151-
:param model: Object detection model wrapped as demonstrated in examples/get_started_yolo.py.
151+
:param model: YOLO v3 or v5 model wrapped as demonstrated in examples/get_started_yolo.py.
152152
The output of the model is `List[Dict[str, torch.Tensor]]`, one for each input image.
153153
The fields of the Dict are as follows:
154154
@@ -290,7 +290,7 @@ def _preprocess_and_convert_inputs(
290290

291291
if not self.channels_first:
292292
x_tensor = torch.permute(x_tensor, (0, 3, 1, 2))
293-
x_tensor /= norm_factor
293+
x_tensor = x_tensor / norm_factor
294294

295295
# Set gradients
296296
if not no_grad:
@@ -311,7 +311,7 @@ def _preprocess_and_convert_inputs(
311311

312312
if not self.channels_first:
313313
x_preprocessed = torch.permute(x_preprocessed, (0, 3, 1, 2))
314-
x_preprocessed /= norm_factor
314+
x_preprocessed = x_preprocessed / norm_factor
315315

316316
# Set gradients
317317
if not no_grad:

0 commit comments

Comments
 (0)