I'm currently following along the PyTorch Tutorial here. As I call fasterrcnn_resnet50_fpn(), I'm getting the following error:
URLError: <urlopen error [WinError 10054] An existing connection was forcibly closed by the remote host>
I first checked the websitetext where the call was trying to download the weights from and indeed there's a connection reset error. I ran windows diagnostics and found that the remote device won't accept the connection. I tried downloading the weights manually and loading the weight path directly but I couldn't get the call to stop downloading the weights from the website.
# load a model pre-trained on COCO
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(weights_path='./fasterrcnn_resnet50_fpn_coco-258fb6c6.pth', )
# replace the classifier with a new one, that has num classes which is 2
num_classes = 2 # 1 class (person) + background
# get number of input features for the classifier
in_features = model.roi_heads.box_predictor.cls_score.in_features
# replace the pre-trained head with a new one
model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
Answering my own question, I found a workaround involving some brute force where we try to connect repeatedly. This took a few tries, but it finally worked. I still do not know why this is happening, but for now, this temporary fix enables the model to be downloaded to the local PyTorch Cache. The code is as follows: