Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
d716c426
Unverified
Commit
d716c426
authored
Dec 09, 2021
by
Kai Zhang
Committed by
GitHub
Dec 09, 2021
Browse files
revamp log api usage method (#5072)
* revamp log api usage method
parent
e0c5cc41
Changes
35
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
27 additions
and
33 deletions
+27
-33
torchvision/models/vgg.py
torchvision/models/vgg.py
+1
-1
torchvision/models/video/resnet.py
torchvision/models/video/resnet.py
+1
-1
torchvision/ops/boxes.py
torchvision/ops/boxes.py
+9
-9
torchvision/ops/deform_conv.py
torchvision/ops/deform_conv.py
+1
-1
torchvision/ops/feature_pyramid_network.py
torchvision/ops/feature_pyramid_network.py
+1
-1
torchvision/ops/focal_loss.py
torchvision/ops/focal_loss.py
+1
-1
torchvision/ops/misc.py
torchvision/ops/misc.py
+3
-3
torchvision/ops/poolers.py
torchvision/ops/poolers.py
+1
-1
torchvision/ops/ps_roi_align.py
torchvision/ops/ps_roi_align.py
+1
-1
torchvision/ops/ps_roi_pool.py
torchvision/ops/ps_roi_pool.py
+1
-1
torchvision/ops/roi_align.py
torchvision/ops/roi_align.py
+1
-1
torchvision/ops/roi_pool.py
torchvision/ops/roi_pool.py
+1
-1
torchvision/ops/stochastic_depth.py
torchvision/ops/stochastic_depth.py
+1
-1
torchvision/prototype/models/vision_transformer.py
torchvision/prototype/models/vision_transformer.py
+1
-1
torchvision/utils.py
torchvision/utils.py
+3
-9
No files found.
torchvision/models/vgg.py
View file @
d716c426
...
...
@@ -37,7 +37,7 @@ class VGG(nn.Module):
self
,
features
:
nn
.
Module
,
num_classes
:
int
=
1000
,
init_weights
:
bool
=
True
,
dropout
:
float
=
0.5
)
->
None
:
super
().
__init__
()
_log_api_usage_once
(
self
)
_log_api_usage_once
(
"models"
,
self
.
__class__
.
__name__
)
self
.
features
=
features
self
.
avgpool
=
nn
.
AdaptiveAvgPool2d
((
7
,
7
))
self
.
classifier
=
nn
.
Sequential
(
...
...
torchvision/models/video/resnet.py
View file @
d716c426
...
...
@@ -209,7 +209,7 @@ class VideoResNet(nn.Module):
zero_init_residual (bool, optional): Zero init bottleneck residual BN. Defaults to False.
"""
super
().
__init__
()
_log_api_usage_once
(
self
)
_log_api_usage_once
(
"models"
,
self
.
__class__
.
__name__
)
self
.
inplanes
=
64
self
.
stem
=
stem
()
...
...
torchvision/ops/boxes.py
View file @
d716c426
...
...
@@ -34,7 +34,7 @@ def nms(boxes: Tensor, scores: Tensor, iou_threshold: float) -> Tensor:
Tensor: int64 tensor with the indices of the elements that have been kept
by NMS, sorted in decreasing order of scores
"""
_log_api_usage_once
(
"
torchvision.ops.
nms"
)
_log_api_usage_once
(
"
ops"
,
"
nms"
)
_assert_has_ops
()
return
torch
.
ops
.
torchvision
.
nms
(
boxes
,
scores
,
iou_threshold
)
...
...
@@ -63,7 +63,7 @@ def batched_nms(
Tensor: int64 tensor with the indices of the elements that have been kept by NMS, sorted
in decreasing order of scores
"""
_log_api_usage_once
(
"
torchvision.ops.
batched_nms"
)
_log_api_usage_once
(
"
ops"
,
"
batched_nms"
)
# Benchmarks that drove the following thresholds are at
# https://github.com/pytorch/vision/issues/1311#issuecomment-781329339
if
boxes
.
numel
()
>
(
4000
if
boxes
.
device
.
type
==
"cpu"
else
20000
)
and
not
torchvision
.
_is_tracing
():
...
...
@@ -122,7 +122,7 @@ def remove_small_boxes(boxes: Tensor, min_size: float) -> Tensor:
Tensor[K]: indices of the boxes that have both sides
larger than min_size
"""
_log_api_usage_once
(
"
torchvision.ops.
remove_small_boxes"
)
_log_api_usage_once
(
"
ops"
,
"
remove_small_boxes"
)
ws
,
hs
=
boxes
[:,
2
]
-
boxes
[:,
0
],
boxes
[:,
3
]
-
boxes
[:,
1
]
keep
=
(
ws
>=
min_size
)
&
(
hs
>=
min_size
)
keep
=
torch
.
where
(
keep
)[
0
]
...
...
@@ -141,7 +141,7 @@ def clip_boxes_to_image(boxes: Tensor, size: Tuple[int, int]) -> Tensor:
Returns:
Tensor[N, 4]: clipped boxes
"""
_log_api_usage_once
(
"
torchvision.ops.
clip_boxes_to_image"
)
_log_api_usage_once
(
"
ops"
,
"
clip_boxes_to_image"
)
dim
=
boxes
.
dim
()
boxes_x
=
boxes
[...,
0
::
2
]
boxes_y
=
boxes
[...,
1
::
2
]
...
...
@@ -182,7 +182,7 @@ def box_convert(boxes: Tensor, in_fmt: str, out_fmt: str) -> Tensor:
Tensor[N, 4]: Boxes into converted format.
"""
_log_api_usage_once
(
"
torchvision.ops.
box_convert"
)
_log_api_usage_once
(
"
ops"
,
"
box_convert"
)
allowed_fmts
=
(
"xyxy"
,
"xywh"
,
"cxcywh"
)
if
in_fmt
not
in
allowed_fmts
or
out_fmt
not
in
allowed_fmts
:
raise
ValueError
(
"Unsupported Bounding Box Conversions for given in_fmt and out_fmt"
)
...
...
@@ -232,7 +232,7 @@ def box_area(boxes: Tensor) -> Tensor:
Returns:
Tensor[N]: the area for each box
"""
_log_api_usage_once
(
"
torchvision.ops.
box_area"
)
_log_api_usage_once
(
"
ops"
,
"
box_area"
)
boxes
=
_upcast
(
boxes
)
return
(
boxes
[:,
2
]
-
boxes
[:,
0
])
*
(
boxes
[:,
3
]
-
boxes
[:,
1
])
...
...
@@ -268,7 +268,7 @@ def box_iou(boxes1: Tensor, boxes2: Tensor) -> Tensor:
Returns:
Tensor[N, M]: the NxM matrix containing the pairwise IoU values for every element in boxes1 and boxes2
"""
_log_api_usage_once
(
"
torchvision.ops.
box_iou"
)
_log_api_usage_once
(
"
ops"
,
"
box_iou"
)
inter
,
union
=
_box_inter_union
(
boxes1
,
boxes2
)
iou
=
inter
/
union
return
iou
...
...
@@ -291,7 +291,7 @@ def generalized_box_iou(boxes1: Tensor, boxes2: Tensor) -> Tensor:
for every element in boxes1 and boxes2
"""
_log_api_usage_once
(
"
torchvision.ops.
generalized_box_iou"
)
_log_api_usage_once
(
"
ops"
,
"
generalized_box_iou"
)
# degenerate boxes gives inf / nan results
# so do an early check
assert
(
boxes1
[:,
2
:]
>=
boxes1
[:,
:
2
]).
all
()
...
...
@@ -323,7 +323,7 @@ def masks_to_boxes(masks: torch.Tensor) -> torch.Tensor:
Returns:
Tensor[N, 4]: bounding boxes
"""
_log_api_usage_once
(
"
torchvision.ops.
masks_to_boxes"
)
_log_api_usage_once
(
"
ops"
,
"
masks_to_boxes"
)
if
masks
.
numel
()
==
0
:
return
torch
.
zeros
((
0
,
4
),
device
=
masks
.
device
,
dtype
=
torch
.
float
)
...
...
torchvision/ops/deform_conv.py
View file @
d716c426
...
...
@@ -61,7 +61,7 @@ def deform_conv2d(
>>> torch.Size([4, 5, 8, 8])
"""
_log_api_usage_once
(
"
torchvision.ops.
deform_conv2d"
)
_log_api_usage_once
(
"
ops"
,
"
deform_conv2d"
)
_assert_has_ops
()
out_channels
=
weight
.
shape
[
0
]
...
...
torchvision/ops/feature_pyramid_network.py
View file @
d716c426
...
...
@@ -77,7 +77,7 @@ class FeaturePyramidNetwork(nn.Module):
extra_blocks
:
Optional
[
ExtraFPNBlock
]
=
None
,
):
super
().
__init__
()
_log_api_usage_once
(
self
)
_log_api_usage_once
(
"ops"
,
self
.
__class__
.
__name__
)
self
.
inner_blocks
=
nn
.
ModuleList
()
self
.
layer_blocks
=
nn
.
ModuleList
()
for
in_channels
in
in_channels_list
:
...
...
torchvision/ops/focal_loss.py
View file @
d716c426
...
...
@@ -32,7 +32,7 @@ def sigmoid_focal_loss(
Returns:
Loss tensor with the reduction option applied.
"""
_log_api_usage_once
(
"
torchvision.ops.
sigmoid_focal_loss"
)
_log_api_usage_once
(
"
ops"
,
"
sigmoid_focal_loss"
)
p
=
torch
.
sigmoid
(
inputs
)
ce_loss
=
F
.
binary_cross_entropy_with_logits
(
inputs
,
targets
,
reduction
=
"none"
)
p_t
=
p
*
targets
+
(
1
-
p
)
*
(
1
-
targets
)
...
...
torchvision/ops/misc.py
View file @
d716c426
...
...
@@ -61,7 +61,7 @@ class FrozenBatchNorm2d(torch.nn.Module):
warnings
.
warn
(
"`n` argument is deprecated and has been renamed `num_features`"
,
DeprecationWarning
)
num_features
=
n
super
().
__init__
()
_log_api_usage_once
(
self
)
_log_api_usage_once
(
"ops"
,
self
.
__class__
.
__name__
)
self
.
eps
=
eps
self
.
register_buffer
(
"weight"
,
torch
.
ones
(
num_features
))
self
.
register_buffer
(
"bias"
,
torch
.
zeros
(
num_features
))
...
...
@@ -155,7 +155,7 @@ class ConvNormActivation(torch.nn.Sequential):
if
activation_layer
is
not
None
:
layers
.
append
(
activation_layer
(
inplace
=
inplace
))
super
().
__init__
(
*
layers
)
_log_api_usage_once
(
self
)
_log_api_usage_once
(
"ops"
,
self
.
__class__
.
__name__
)
self
.
out_channels
=
out_channels
...
...
@@ -179,7 +179,7 @@ class SqueezeExcitation(torch.nn.Module):
scale_activation
:
Callable
[...,
torch
.
nn
.
Module
]
=
torch
.
nn
.
Sigmoid
,
)
->
None
:
super
().
__init__
()
_log_api_usage_once
(
self
)
_log_api_usage_once
(
"ops"
,
self
.
__class__
.
__name__
)
self
.
avgpool
=
torch
.
nn
.
AdaptiveAvgPool2d
(
1
)
self
.
fc1
=
torch
.
nn
.
Conv2d
(
input_channels
,
squeeze_channels
,
1
)
self
.
fc2
=
torch
.
nn
.
Conv2d
(
squeeze_channels
,
input_channels
,
1
)
...
...
torchvision/ops/poolers.py
View file @
d716c426
...
...
@@ -276,7 +276,7 @@ class MultiScaleRoIAlign(nn.Module):
canonical_level
:
int
=
4
,
):
super
().
__init__
()
_log_api_usage_once
(
self
)
_log_api_usage_once
(
"ops"
,
self
.
__class__
.
__name__
)
if
isinstance
(
output_size
,
int
):
output_size
=
(
output_size
,
output_size
)
self
.
featmap_names
=
featmap_names
...
...
torchvision/ops/ps_roi_align.py
View file @
d716c426
...
...
@@ -43,7 +43,7 @@ def ps_roi_align(
Returns:
Tensor[K, C / (output_size[0] * output_size[1]), output_size[0], output_size[1]]: The pooled RoIs
"""
_log_api_usage_once
(
"
torchvision.ops.
ps_roi_align"
)
_log_api_usage_once
(
"
ops"
,
"
ps_roi_align"
)
_assert_has_ops
()
check_roi_boxes_shape
(
boxes
)
rois
=
boxes
...
...
torchvision/ops/ps_roi_pool.py
View file @
d716c426
...
...
@@ -37,7 +37,7 @@ def ps_roi_pool(
Returns:
Tensor[K, C / (output_size[0] * output_size[1]), output_size[0], output_size[1]]: The pooled RoIs.
"""
_log_api_usage_once
(
"
torchvision.ops.
ps_roi_pool"
)
_log_api_usage_once
(
"
ops"
,
"
ps_roi_pool"
)
_assert_has_ops
()
check_roi_boxes_shape
(
boxes
)
rois
=
boxes
...
...
torchvision/ops/roi_align.py
View file @
d716c426
...
...
@@ -50,7 +50,7 @@ def roi_align(
Returns:
Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs.
"""
_log_api_usage_once
(
"
torchvision.ops.
roi_align"
)
_log_api_usage_once
(
"
ops"
,
"
roi_align"
)
_assert_has_ops
()
check_roi_boxes_shape
(
boxes
)
rois
=
boxes
...
...
torchvision/ops/roi_pool.py
View file @
d716c426
...
...
@@ -39,7 +39,7 @@ def roi_pool(
Returns:
Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs.
"""
_log_api_usage_once
(
"
torchvision.ops.
roi_pool"
)
_log_api_usage_once
(
"
ops"
,
"
roi_pool"
)
_assert_has_ops
()
check_roi_boxes_shape
(
boxes
)
rois
=
boxes
...
...
torchvision/ops/stochastic_depth.py
View file @
d716c426
...
...
@@ -23,7 +23,7 @@ def stochastic_depth(input: Tensor, p: float, mode: str, training: bool = True)
Returns:
Tensor[N, ...]: The randomly zeroed tensor.
"""
_log_api_usage_once
(
"
torchvision.ops.
stochastic_depth"
)
_log_api_usage_once
(
"
ops"
,
"
stochastic_depth"
)
if
p
<
0.0
or
p
>
1.0
:
raise
ValueError
(
f
"drop probability has to be between 0 and 1, but got
{
p
}
"
)
if
mode
not
in
[
"batch"
,
"row"
]:
...
...
torchvision/prototype/models/vision_transformer.py
View file @
d716c426
...
...
@@ -140,7 +140,7 @@ class VisionTransformer(nn.Module):
norm_layer
:
Callable
[...,
torch
.
nn
.
Module
]
=
partial
(
nn
.
LayerNorm
,
eps
=
1e-6
),
):
super
().
__init__
()
_log_api_usage_once
(
self
)
_log_api_usage_once
(
"models"
,
self
.
__class__
.
__name__
)
torch
.
_assert
(
image_size
%
patch_size
==
0
,
"Input shape indivisible by patch size!"
)
self
.
image_size
=
image_size
self
.
patch_size
=
patch_size
...
...
torchvision/utils.py
View file @
d716c426
import
math
import
pathlib
import
warnings
from
typing
import
Union
,
Optional
,
List
,
Tuple
,
BinaryIO
,
no_type_check
from
typing
import
Union
,
Optional
,
List
,
Tuple
,
BinaryIO
import
numpy
as
np
import
torch
...
...
@@ -375,13 +375,7 @@ def _generate_color_palette(num_masks: int):
return
[
tuple
((
i
*
palette
)
%
255
)
for
i
in
range
(
num_masks
)]
@
no_type_check
def
_log_api_usage_once
(
obj
:
str
)
->
None
:
# type: ignore
def
_log_api_usage_once
(
module
:
str
,
name
:
str
)
->
None
:
if
torch
.
jit
.
is_scripting
()
or
torch
.
jit
.
is_tracing
():
return
# NOTE: obj can be an object as well, but mocking it here to be
# only a string to appease torchscript
if
isinstance
(
obj
,
str
):
torch
.
_C
.
_log_api_usage_once
(
obj
)
else
:
torch
.
_C
.
_log_api_usage_once
(
f
"
{
obj
.
__module__
}
.
{
obj
.
__class__
.
__name__
}
"
)
torch
.
_C
.
_log_api_usage_once
(
f
"torchvision.
{
module
}
.
{
name
}
"
)
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment