Skip to content

Commit 912dafb

Browse files
authored
Merge branch 'main' into check-rotate-autodiff
2 parents 7bd8d65 + 55f7faf commit 912dafb

File tree

29 files changed

+390
-69
lines changed

29 files changed

+390
-69
lines changed

.circleci/unittest/linux/scripts/environment.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ dependencies:
99
- libpng
1010
- jpeg
1111
- ca-certificates
12-
# TODO: remove this after https://github.com/pytorch/pytorch/issues/69905 is resolved
13-
- pyyaml
1412
- pip:
1513
- future
1614
- pillow >=5.3.0, !=8.3.*

.circleci/unittest/windows/scripts/environment.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ dependencies:
99
- libpng
1010
- jpeg
1111
- ca-certificates
12-
# TODO: remove this after https://github.com/pytorch/pytorch/issues/69905 is resolved
13-
- pyyaml
1412
- pip:
1513
- future
1614
- pillow >=5.3.0, !=8.3.*

references/classification/sampler.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class RASampler(torch.utils.data.Sampler):
1515
https://github.com/facebookresearch/deit/blob/main/samplers.py
1616
"""
1717

18-
def __init__(self, dataset, num_replicas=None, rank=None, shuffle=True, seed=0):
18+
def __init__(self, dataset, num_replicas=None, rank=None, shuffle=True, seed=0, repetitions=3):
1919
if num_replicas is None:
2020
if not dist.is_available():
2121
raise RuntimeError("Requires distributed package to be available!")
@@ -28,11 +28,12 @@ def __init__(self, dataset, num_replicas=None, rank=None, shuffle=True, seed=0):
2828
self.num_replicas = num_replicas
2929
self.rank = rank
3030
self.epoch = 0
31-
self.num_samples = int(math.ceil(len(self.dataset) * 3.0 / self.num_replicas))
31+
self.num_samples = int(math.ceil(len(self.dataset) * float(repetitions) / self.num_replicas))
3232
self.total_size = self.num_samples * self.num_replicas
3333
self.num_selected_samples = int(math.floor(len(self.dataset) // 256 * 256 / self.num_replicas))
3434
self.shuffle = shuffle
3535
self.seed = seed
36+
self.repetitions = repetitions
3637

3738
def __iter__(self):
3839
# Deterministically shuffle based on epoch
@@ -44,7 +45,7 @@ def __iter__(self):
4445
indices = list(range(len(self.dataset)))
4546

4647
# Add extra samples to make it evenly divisible
47-
indices = [ele for ele in indices for i in range(3)]
48+
indices = [ele for ele in indices for i in range(self.repetitions)]
4849
indices += indices[: (self.total_size - len(indices))]
4950
assert len(indices) == self.total_size
5051

references/classification/train.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def load_data(traindir, valdir, args):
174174
print("Creating data loaders")
175175
if args.distributed:
176176
if args.ra_sampler:
177-
train_sampler = RASampler(dataset, shuffle=True)
177+
train_sampler = RASampler(dataset, shuffle=True, repetitions=args.ra_reps)
178178
else:
179179
train_sampler = torch.utils.data.distributed.DistributedSampler(dataset)
180180
test_sampler = torch.utils.data.distributed.DistributedSampler(dataset_test, shuffle=False)
@@ -485,7 +485,10 @@ def get_args_parser(add_help=True):
485485
"--train-crop-size", default=224, type=int, help="the random crop size used for training (default: 224)"
486486
)
487487
parser.add_argument("--clip-grad-norm", default=None, type=float, help="the maximum gradient norm (default None)")
488-
parser.add_argument("--ra-sampler", action="store_true", help="whether to use ra_sampler in training")
488+
parser.add_argument("--ra-sampler", action="store_true", help="whether to use Repeated Augmentation in training")
489+
parser.add_argument(
490+
"--ra-reps", default=3, type=int, help="number of repetitions for Repeated Augmentation (default: 3)"
491+
)
489492

490493
# Prototype models only
491494
parser.add_argument("--weights", default=None, type=str, help="the weights enum name to load")

torchvision/csrc/io/image/cpu/decode_jpeg.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ static void torch_jpeg_set_source_mgr(
7070
} // namespace
7171

7272
torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
73+
C10_LOG_API_USAGE_ONCE(
74+
"torchvision.csrc.io.image.cpu.decode_jpeg.decode_jpeg");
7375
// Check that the input tensor dtype is uint8
7476
TORCH_CHECK(data.dtype() == torch::kU8, "Expected a torch.uint8 tensor");
7577
// Check that the input tensor is 1-dimensional

torchvision/csrc/io/image/cpu/decode_png.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ torch::Tensor decode_png(
2323
const torch::Tensor& data,
2424
ImageReadMode mode,
2525
bool allow_16_bits) {
26+
C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.image.cpu.decode_png.decode_png");
2627
// Check that the input tensor dtype is uint8
2728
TORCH_CHECK(data.dtype() == torch::kU8, "Expected a torch.uint8 tensor");
2829
// Check that the input tensor is 1-dimensional

torchvision/csrc/io/image/cpu/encode_jpeg.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ using JpegSizeType = size_t;
2525
using namespace detail;
2626

2727
torch::Tensor encode_jpeg(const torch::Tensor& data, int64_t quality) {
28+
C10_LOG_API_USAGE_ONCE(
29+
"torchvision.csrc.io.image.cpu.encode_jpeg.encode_jpeg");
2830
// Define compression structures and error handling
2931
struct jpeg_compress_struct cinfo {};
3032
struct torch_jpeg_error_mgr jerr {};

torchvision/csrc/io/image/cpu/encode_png.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void torch_png_write_data(
6363
} // namespace
6464

6565
torch::Tensor encode_png(const torch::Tensor& data, int64_t compression_level) {
66+
C10_LOG_API_USAGE_ONCE("torchvision.csrc.io.image.cpu.encode_png.encode_png");
6667
// Define compression structures and error handling
6768
png_structp png_write;
6869
png_infop info_ptr;

torchvision/csrc/io/image/cpu/read_write_file.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ std::wstring utf8_decode(const std::string& str) {
3333
#endif
3434

3535
torch::Tensor read_file(const std::string& filename) {
36+
C10_LOG_API_USAGE_ONCE(
37+
"torchvision.csrc.io.image.cpu.read_write_file.read_file");
3638
#ifdef _WIN32
3739
// According to
3840
// https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019,
@@ -76,6 +78,8 @@ torch::Tensor read_file(const std::string& filename) {
7678
}
7779

7880
void write_file(const std::string& filename, torch::Tensor& data) {
81+
C10_LOG_API_USAGE_ONCE(
82+
"torchvision.csrc.io.image.cpu.read_write_file.write_file");
7983
// Check that the input tensor is on CPU
8084
TORCH_CHECK(data.device() == torch::kCPU, "Input tensor should be on CPU");
8185

torchvision/csrc/io/image/cuda/decode_jpeg_cuda.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ torch::Tensor decode_jpeg_cuda(
3333
const torch::Tensor& data,
3434
ImageReadMode mode,
3535
torch::Device device) {
36+
C10_LOG_API_USAGE_ONCE(
37+
"torchvision.csrc.io.image.cuda.decode_jpeg_cuda.decode_jpeg_cuda");
3638
TORCH_CHECK(data.dtype() == torch::kU8, "Expected a torch.uint8 tensor");
3739

3840
TORCH_CHECK(

0 commit comments

Comments
 (0)