Skip to content

Commit 116a54b

Browse files
galqiwiNicolasHugSvetlana Karslioglu
authored
Changed deprecated argument "pretrained" to non-deprecated argument "weights" for torchvision models (#2263)
* changed depricated pretrained argument to weights * Update intermediate_source/flask_rest_api_tutorial.py Co-authored-by: Nicolas Hug <contact@nicolas-hug.com> --------- Co-authored-by: Nicolas Hug <contact@nicolas-hug.com> Co-authored-by: Svetlana Karslioglu <svekars@fb.com>
1 parent f5bfe66 commit 116a54b

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

beginner_source/basics/saveloadrun_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
# state dictionary, called ``state_dict``. These can be persisted via the ``torch.save``
2727
# method:
2828

29-
model = models.vgg16(pretrained=True)
29+
model = models.vgg16(weights='IMAGENET1K_V1')
3030
torch.save(model.state_dict(), 'model_weights.pth')
3131

3232
##########################
3333
# To load model weights, you need to create an instance of the same model first, and then load the parameters
3434
# using ``load_state_dict()`` method.
3535

36-
model = models.vgg16() # we do not specify pretrained=True, i.e. do not load default weights
36+
model = models.vgg16() # we do not specify weights, i.e. create untrained model
3737
model.load_state_dict(torch.load('model_weights.pth'))
3838
model.eval()
3939

beginner_source/introyt/captumyt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
# now.
156156
#
157157

158-
model = models.resnet101(pretrained=True)
158+
model = models.resnet101(weights='IMAGENET1K_V1')
159159
model = model.eval()
160160

161161

beginner_source/transfer_learning_tutorial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def visualize_model(model, num_images=6):
250250
# Load a pretrained model and reset final fully connected layer.
251251
#
252252

253-
model_ft = models.resnet18(pretrained=True)
253+
model_ft = models.resnet18(weights='IMAGENET1K_V1')
254254
num_ftrs = model_ft.fc.in_features
255255
# Here the size of each output sample is set to 2.
256256
# Alternatively, it can be generalized to nn.Linear(num_ftrs, len(class_names)).
@@ -295,7 +295,7 @@ def visualize_model(model, num_images=6):
295295
# `here <https://pytorch.org/docs/notes/autograd.html#excluding-subgraphs-from-backward>`__.
296296
#
297297

298-
model_conv = torchvision.models.resnet18(pretrained=True)
298+
model_conv = torchvision.models.resnet18(weights='IMAGENET1K_V1')
299299
for param in model_conv.parameters():
300300
param.requires_grad = False
301301

intermediate_source/flask_rest_api_tutorial.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def transform_image(image_bytes):
161161

162162
from torchvision import models
163163

164-
# Make sure to pass `pretrained` as `True` to use the pretrained weights:
165-
model = models.densenet121(pretrained=True)
164+
# Make sure to set `weights` as `'IMAGENET1K_V1'` to use the pretrained weights:
165+
model = models.densenet121(weights='IMAGENET1K_V1')
166166
# Since we are using our model only for inference, switch to `eval` mode:
167167
model.eval()
168168

@@ -269,7 +269,7 @@ def get_prediction(image_bytes):
269269
#
270270
# app = Flask(__name__)
271271
# imagenet_class_index = json.load(open('<PATH/TO/.json/FILE>/imagenet_class_index.json'))
272-
# model = models.densenet121(pretrained=True)
272+
# model = models.densenet121(weights='IMAGENET1K_V1')
273273
# model.eval()
274274
#
275275
#

intermediate_source/tensorboard_profiler_tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
# To run on GPU, move model and loss to GPU device.
6969

7070
device = torch.device("cuda:0")
71-
model = torchvision.models.resnet18(pretrained=True).cuda(device)
71+
model = torchvision.models.resnet18(weights='IMAGENET1K_V1').cuda(device)
7272
criterion = torch.nn.CrossEntropyLoss().cuda(device)
7373
optimizer = torch.optim.SGD(model.parameters(), lr=0.001, momentum=0.9)
7474
model.train()

0 commit comments

Comments
 (0)