Skip to content

Commit 24f076f

Browse files
committed
Merge branch 'master' of https://github.com/pytorch/vision into add_msks
2 parents ba9db12 + b2cf604 commit 24f076f

File tree

8 files changed

+53
-29
lines changed

8 files changed

+53
-29
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ jobs:
140140
curl https://oss-clang-format.s3.us-east-2.amazonaws.com/linux64/clang-format-linux64 -o clang-format
141141
chmod +x clang-format
142142
sudo mv clang-format /opt/clang-format
143-
./travis-scripts/run-clang-format/run-clang-format.py -r torchvision/csrc --clang-format-executable /opt/clang-format
143+
./.circleci/unittest/linux/scripts/run-clang-format.py -r torchvision/csrc --clang-format-executable /opt/clang-format
144144
145145
torchhub_test:
146146
docker:

.circleci/config.yml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ jobs:
140140
curl https://oss-clang-format.s3.us-east-2.amazonaws.com/linux64/clang-format-linux64 -o clang-format
141141
chmod +x clang-format
142142
sudo mv clang-format /opt/clang-format
143-
./travis-scripts/run-clang-format/run-clang-format.py -r torchvision/csrc --clang-format-executable /opt/clang-format
143+
./.circleci/unittest/linux/scripts/run-clang-format.py -r torchvision/csrc --clang-format-executable /opt/clang-format
144144

145145
torchhub_test:
146146
docker:

travis-scripts/run-clang-format/run-clang-format.py renamed to .circleci/unittest/linux/scripts/run-clang-format.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
#!/usr/bin/env python
2+
"""
3+
MIT License
4+
5+
Copyright (c) 2017 Guillaume Papin
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.
24+
"""
225
"""A wrapper script around clang-format, suitable for linting multiple files
326
and to use for continuous integration.
427

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ gen.yml
2525
.idea/
2626
*.orig
2727
*-checkpoint.ipynb
28+
*.venv
57 Bytes
Loading

test/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_draw_boxes(self):
8686
[10, 15, 30, 35], [23, 35, 93, 95]], dtype=torch.float)
8787
labels = ["a", "b", "c", "d"]
8888
colors = ["green", "#FF00FF", (0, 255, 0), "red"]
89-
result = utils.draw_bounding_boxes(img, boxes, labels=labels, colors=colors)
89+
result = utils.draw_bounding_boxes(img, boxes, labels=labels, colors=colors, fill=True)
9090

9191
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "assets", "fakedata", "draw_boxes_util.png")
9292
if not os.path.exists(path):

torchvision/utils.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import math
55
import warnings
66
import numpy as np
7-
from PIL import Image, ImageDraw
8-
from PIL import ImageFont
7+
from PIL import Image, ImageDraw, ImageFont, ImageColor
98

109
__all__ = ["make_grid", "save_image", "draw_bounding_boxes", "draw_segmentation_masks"]
1110

@@ -142,6 +141,7 @@ def draw_bounding_boxes(
142141
boxes: torch.Tensor,
143142
labels: Optional[List[str]] = None,
144143
colors: Optional[List[Union[str, Tuple[int, int, int]]]] = None,
144+
fill: Optional[bool] = False,
145145
width: int = 1,
146146
font: Optional[str] = None,
147147
font_size: int = 10
@@ -150,6 +150,7 @@ def draw_bounding_boxes(
150150
"""
151151
Draws bounding boxes on given image.
152152
The values of the input image should be uint8 between 0 and 255.
153+
If filled, Resulting Tensor should be saved as PNG image.
153154
154155
Args:
155156
image (Tensor): Tensor of shape (C x H x W)
@@ -159,6 +160,7 @@ def draw_bounding_boxes(
159160
labels (List[str]): List containing the labels of bounding boxes.
160161
colors (List[Union[str, Tuple[int, int, int]]]): List containing the colors of bounding boxes. The colors can
161162
be represented as `str` or `Tuple[int, int, int]`.
163+
fill (bool): If `True` fills the bounding box with specified color.
162164
width (int): Width of bounding box.
163165
font (str): A filename containing a TrueType font. If the file is not found in this filename, the loader may
164166
also search in other directories, such as the `fonts/` directory on Windows or `/Library/Fonts/`,
@@ -178,12 +180,31 @@ def draw_bounding_boxes(
178180

179181
img_boxes = boxes.to(torch.int64).tolist()
180182

181-
draw = ImageDraw.Draw(img_to_draw)
183+
if fill:
184+
draw = ImageDraw.Draw(img_to_draw, "RGBA")
185+
186+
else:
187+
draw = ImageDraw.Draw(img_to_draw)
188+
182189
txt_font = ImageFont.load_default() if font is None else ImageFont.truetype(font=font, size=font_size)
183190

184191
for i, bbox in enumerate(img_boxes):
185-
color = None if colors is None else colors[i]
186-
draw.rectangle(bbox, width=width, outline=color)
192+
if colors is None:
193+
color = None
194+
else:
195+
color = colors[i]
196+
197+
if fill:
198+
if color is None:
199+
fill_color = (255, 255, 255, 100)
200+
elif isinstance(color, str):
201+
# This will automatically raise Error if rgb cannot be parsed.
202+
fill_color = ImageColor.getrgb(color) + (100,)
203+
elif isinstance(color, tuple):
204+
fill_color = color + (100,)
205+
draw.rectangle(bbox, width=width, outline=color, fill=fill_color)
206+
else:
207+
draw.rectangle(bbox, width=width, outline=color)
187208

188209
if labels is not None:
189210
draw.text((bbox[0], bbox[1]), labels[i], fill=color, font=txt_font)

travis-scripts/run-clang-format/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)