错误403:尝试在Google colab中加载预训练模型时被禁止

时间:2020-02-12 04:18:12

标签: pytorch google-colaboratory

这是我的代码,用于在Google Colab笔记本中加载预先训练的模型L

# Import resources
%matplotlib inline
%config InlineBackend.figure_format = 'retina'
import time
import json
import copy
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import PIL
from PIL import Image
from collections import OrderedDict
import torch
from torch import nn, optim, cuda
from torch.optim import lr_scheduler
from torch.autograd import Variable
import torchvision
from torchvision import datasets, models, transforms
from torch.utils.data.sampler import SubsetRandomSampler
import torch.nn as nn
import torch.nn.functional as F
import os

device = torch.device("cuda" if torch.cuda.is_available() 
                                  else "cpu")
print(device)

model = models.resnet152(pretrained=True) 
num_in_features = 2048
print(model)

我在成功运行此行之前,但是现在出现错误:

Downloading: "https://download.pytorch.org/models/resnet152-b121ed2d.pth" to /root/.cache/torch/checkpoints/resnet152-b121ed2d.pth
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-13-361fc480b515> in <module>()
----> 1 model = models.resnet152(pretrained=True)
      2 num_in_features = 2048
      3 print(model)

9 frames
/usr/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    648 class HTTPDefaultErrorHandler(BaseHandler):
    649     def http_error_default(self, req, fp, code, msg, hdrs):
--> 650         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    651 
    652 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 403: Forbidden

我尝试过以其他各种方式加载模型,启动新笔记本和!kill -9 -1

我是Google Colab的新手,所以不确定这里到底是什么问题!预先感谢

1 个答案:

答案 0 :(得分:0)

对于很多人来说,这似乎是一个问题,现在已经解决了!