Skip to content

Commit b5bf8fc

Browse files
authored
Merge branch 'main' into transforms/mixupcutmix
2 parents 9abb18b + 719e120 commit b5bf8fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+508
-86
lines changed

.circleci/config.yml

Lines changed: 3 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.circleci/config.yml.in

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ commands:
4545
our_upload_channel=test
4646
fi
4747
echo "export UPLOAD_CHANNEL=${our_upload_channel}" >> ${BASH_ENV}
48-
install_cuda_compatible_cmath:
49-
description: "Install CUDA compatible cmath"
50-
steps:
51-
- run:
52-
name: _HACK_ Install CUDA compatible cmath
53-
no_output_timeout: 1m
54-
command: |
55-
powershell .circleci/scripts/vs_install_cmath.ps1
5648

5749
brew_update:
5850
description: "Update Homebrew and install base formulae"
@@ -192,8 +184,9 @@ jobs:
192184
- checkout
193185
- run:
194186
command: |
195-
pip install --user --progress-bar off flake8 typing
196-
flake8 --config=setup.cfg .
187+
pip install --user --progress-bar off pre-commit
188+
pre-commit install-hooks
189+
- run: pre-commit run --all-files
197190

198191
python_type_check:
199192
docker:
@@ -300,7 +293,6 @@ jobs:
300293
steps:
301294
- checkout_merge
302295
- designate_upload_channel
303-
- install_cuda_compatible_cmath
304296
- run:
305297
name: Build conda packages
306298
no_output_timeout: 20m
@@ -332,7 +324,6 @@ jobs:
332324
steps:
333325
- checkout_merge
334326
- designate_upload_channel
335-
- install_cuda_compatible_cmath
336327
- run:
337328
name: Build wheel packages
338329
command: |
@@ -712,7 +703,6 @@ jobs:
712703
steps:
713704
- checkout
714705
- designate_upload_channel
715-
- install_cuda_compatible_cmath
716706
- run:
717707
name: Generate cache key
718708
# This will refresh cache on Sundays, nightly build should generate new cache.
@@ -754,7 +744,6 @@ jobs:
754744
steps:
755745
- checkout
756746
- designate_upload_channel
757-
- install_cuda_compatible_cmath
758747
- run:
759748
name: Generate cache key
760749
# This will refresh cache on Sundays, nightly build should generate new cache.
@@ -884,7 +873,6 @@ jobs:
884873
steps:
885874
- checkout_merge
886875
- designate_upload_channel
887-
- install_cuda_compatible_cmath
888876
- run:
889877
command: |
890878
set -ex
@@ -898,7 +886,6 @@ jobs:
898886
steps:
899887
- checkout_merge
900888
- designate_upload_channel
901-
- install_cuda_compatible_cmath
902889
- run:
903890
command: |
904891
set -ex

.circleci/scripts/vs_install_cmath.ps1

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

.circleci/unittest/linux/scripts/run-clang-format.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
SOFTWARE.
24-
"""
25-
"""A wrapper script around clang-format, suitable for linting multiple files
24+
25+
A wrapper script around clang-format, suitable for linting multiple files
2626
and to use for continuous integration.
2727
2828
This is an alternative API for the clang-format command line.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
start /wait "" "%miniconda_exe%" /S /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /D=%tmp_conda%
1+
start /wait "" "%miniconda_exe%" /S /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /D=%tmp_conda%

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://gitlab.com/pycqa/flake8
3+
rev: 3.9.2
4+
hooks:
5+
- id: flake8
6+
args: [--config=setup.cfg]
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v4.0.1
9+
hooks:
10+
- id: check-docstring-first
11+
- id: check-toml
12+
- id: check-yaml
13+
exclude: packaging/.*
14+
- id: end-of-file-fixer

CONTRIBUTING.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ If you plan to modify the code or documentation, please follow the steps below:
6464
2. If you have modified the code (new feature or bug-fix), please add unit tests.
6565
3. If you have changed APIs, update the documentation. Make sure the documentation builds.
6666
4. Ensure the test suite passes.
67-
5. Make sure your code passes `flake8` formatting check.
67+
5. Make sure your code passes the formatting checks (see below).
6868

6969
For more details about pull requests,
7070
please read [GitHub's guides](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request).
@@ -75,9 +75,19 @@ If you would like to contribute a new dataset, please see [here](#New-dataset).
7575

7676
### Code formatting and typing
7777

78-
New code should be compatible with Python 3.X versions and be compliant with PEP8. To check the codebase, please run
78+
Contributions should be compatible with Python 3.X versions and be compliant with PEP8. To check the codebase, please
79+
either run
7980
```bash
80-
flake8 --config=setup.cfg .
81+
pre-commit run --all-files
82+
```
83+
or run
84+
```bash
85+
pre-commit install
86+
```
87+
once to perform these checks automatically before every `git commit`. If `pre-commit` is not available you can install
88+
it with
89+
```
90+
pip install pre-commit
8191
```
8292

8393
The codebase has type annotations, please make sure to add type hints if required. We use `mypy` tool for type checking:

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ otherwise, add the include and library paths in the environment variables ``TORC
106106
.. _libjpeg: http://ijg.org/
107107
.. _libjpeg-turbo: https://libjpeg-turbo.org/
108108

109-
C++ API
110-
=======
111-
TorchVision also offers a C++ API that contains C++ equivalent of python models.
109+
Using the models on C++
110+
=======================
111+
TorchVision provides an example project for how to use the models on C++ using JIT Script.
112112

113113
Installation From source:
114114

android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,3 @@ allprojects {
3939
ext.deps = [
4040
jsr305: 'com.google.code.findbugs:jsr305:3.0.1',
4141
]
42-

android/test_app/app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
android:background="@android:color/black"
1515
android:textColor="@android:color/white" />
1616

17-
</FrameLayout>
17+
</FrameLayout>

docs/source/_static/css/custom_torchvision.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ torchvision it just hides the links. So we have to put them back here */
99
article.pytorch-article .sphx-glr-download-link-note.admonition.note,
1010
article.pytorch-article .reference.download.internal, article.pytorch-article .sphx-glr-signature {
1111
display: block;
12-
}
12+
}

docs/source/_static/img/pytorch-logo-flame.svg

Lines changed: 1 addition & 1 deletion
Loading

docs/source/datasets.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,17 @@ KMNIST
147147

148148
.. autoclass:: KMNIST
149149

150+
LFW
151+
~~~~~
152+
153+
.. autoclass:: LFWPeople
154+
:members: __getitem__
155+
:special-members:
156+
157+
.. autoclass:: LFWPairs
158+
:members: __getitem__
159+
:special-members:
160+
150161
LSUN
151162
~~~~
152163

docs/source/feature_extraction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ API Reference
126126

127127
.. autofunction:: create_feature_extractor
128128

129-
.. autofunction:: get_graph_node_names
129+
.. autofunction:: get_graph_node_names

examples/cpp/hello_world/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ Once both dependencies are sorted, we can start the CMake fun:
1616

1717
| That's it!
1818
| You should now have a ``hello-world`` executable in your ``build`` folder.
19-
Running it will output a (fairly long) tensor of random values to your terminal.
19+
Running it will output a (fairly long) tensor of random values to your terminal.

examples/cpp/hello_world/main.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,44 @@
11
#include <iostream>
2+
#include <torch/script.h>
23
#include <torch/torch.h>
34
#include <torchvision/vision.h>
4-
#include <torchvision/models/resnet.h>
55

6-
int main()
7-
{
8-
auto model = vision::models::ResNet18();
9-
model->eval();
6+
int main() {
7+
torch::DeviceType device_type;
8+
device_type = torch::kCPU;
109

11-
// Create a random input tensor and run it through the model.
12-
auto in = torch::rand({1, 3, 10, 10});
13-
auto out = model->forward(in);
10+
torch::jit::script::Module model;
11+
try {
12+
std::cout << "Loading model\n";
13+
// Deserialize the ScriptModule from a file using torch::jit::load().
14+
model = torch::jit::load("resnet18.pt");
15+
std::cout << "Model loaded\n";
16+
} catch (const torch::Error& e) {
17+
std::cout << "error loading the model\n";
18+
return -1;
19+
} catch (const std::exception& e) {
20+
std::cout << "Other error: " << e.what() << "\n";
21+
return -1;
22+
}
1423

15-
std::cout << out.sizes();
24+
// TorchScript models require a List[IValue] as input
25+
std::vector<torch::jit::IValue> inputs;
26+
27+
// Create a random input tensor and run it through the model.
28+
inputs.push_back(torch::rand({1, 3, 10, 10}));
29+
auto out = model.forward(inputs);
30+
std::cout << out << "\n";
1631

1732
if (torch::cuda::is_available()) {
1833
// Move model and inputs to GPU
19-
model->to(torch::kCUDA);
20-
auto gpu_in = in.to(torch::kCUDA);
21-
auto gpu_out = model->forward(gpu_in);
34+
model.to(torch::kCUDA);
35+
36+
// Add GPU inputs
37+
inputs.clear();
38+
torch::TensorOptions options = torch::TensorOptions{torch::kCUDA};
39+
inputs.push_back(torch::rand({1, 3, 10, 10}, options));
2240

23-
std::cout << gpu_out.sizes();
41+
auto gpu_out = model.forward(inputs);
42+
std::cout << gpu_out << "\n";
2443
}
2544
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import os.path as osp
2+
3+
import torch
4+
import torchvision
5+
6+
HERE = osp.dirname(osp.abspath(__file__))
7+
ASSETS = osp.dirname(osp.dirname(HERE))
8+
9+
model = torchvision.models.resnet18(pretrained=False)
10+
model.eval()
11+
12+
traced_model = torch.jit.script(model)
13+
traced_model.save("resnet18.pt")

examples/python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Python examples
22

33
The examples in this directory have been moved online in our [gallery
4-
page](https://pytorch.org/vision/stable/auto_examples/index.html).
4+
page](https://pytorch.org/vision/stable/auto_examples/index.html).

gallery/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Example gallery
22
===============
33

4-
Below is a gallery of examples
4+
Below is a gallery of examples

gallery/assets/imagenet_class_index.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

ios/VisionTestApp/VisionTestApp/ViewController.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55

66

77
@end
8-

packaging/build_cmake.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ fi
9898
# Compile and run the CPP example
9999
popd
100100
cd examples/cpp/hello_world
101-
102101
mkdir build
102+
103+
# Trace model
104+
python trace_model.py
105+
cp resnet18.pt build
106+
103107
cd build
104108
cmake .. -DTorch_DIR=$TORCH_PATH/share/cmake/Torch
105109

106110
if [[ "$OSTYPE" == "msys" ]]; then
107111
"$script_dir/windows/internal/vc_env_helper.bat" "$script_dir/windows/internal/build_cpp_example.bat" $PARALLELISM
112+
mv resnet18.pt Release
108113
cd Release
109114
else
110115
make -j$PARALLELISM

0 commit comments

Comments
 (0)