From 1a94447ebe381eef7fed1e4ce542cbefeb5fdc5a Mon Sep 17 00:00:00 2001 From: Omar Clinton Date: Sat, 27 Mar 2021 20:44:00 -0700 Subject: [PATCH 1/2] Allow path to be buffer. This is to allow models to be downloaded as strings. See https://stackoverflow.com/questions/57898998/is-it-possible-to-load-a-pretrained-pytorch-model-from-a-gcs-bucket-url-without --- fvcore/common/checkpoint.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fvcore/common/checkpoint.py b/fvcore/common/checkpoint.py index 06fde35..8a96db2 100644 --- a/fvcore/common/checkpoint.py +++ b/fvcore/common/checkpoint.py @@ -3,6 +3,7 @@ import logging import os +import io from collections import defaultdict from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple @@ -136,7 +137,7 @@ def load( self.logger.info("No checkpoint found. Initializing model from scratch") return {} self.logger.info("Loading checkpoint from {}".format(path)) - if not os.path.isfile(path): + if not os.path.isfile(path) and not isinstance(path, io.BytesIO): path = self.path_manager.get_local_path(path) assert os.path.isfile(path), "Checkpoint {} not found!".format(path) From 8b43c94db4527a86d125fcdc38ae4bb08fab090c Mon Sep 17 00:00:00 2001 From: Omar Clinton Date: Sat, 27 Mar 2021 20:53:18 -0700 Subject: [PATCH 2/2] lint issue --- fvcore/common/checkpoint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fvcore/common/checkpoint.py b/fvcore/common/checkpoint.py index 8a96db2..4b6de38 100644 --- a/fvcore/common/checkpoint.py +++ b/fvcore/common/checkpoint.py @@ -1,9 +1,9 @@ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. # pyre-ignore-all-errors[2,3] +import io import logging import os -import io from collections import defaultdict from typing import Any, Dict, Iterable, List, NamedTuple, Optional, Tuple