Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions models/public/regnetx-3.2gf/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pycls.core.checkpoint
import torch
import pycls.core.config
import pycls.models.model_zoo
from pycls.core.checkpoint import unwrap_model

def regnet(config_path, weights_path):
pycls.core.config.cfg.merge_from_file(config_path)
model = pycls.models.model_zoo.RegNet()
pycls.core.checkpoint.load_checkpoint(weights_path, model)
checkpoint = torch.load(weights_path, map_location="cpu", weights_only=False)
test_err = checkpoint.get("test_err", 100)
ema_err = checkpoint.get("ema_err", 100)
ema_state = "ema_state" if "ema_state" in checkpoint else "model_state"
best_state = "model_state" if test_err <= ema_err else ema_state
unwrap_model(model).load_state_dict(checkpoint[best_state])
return model
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def load_model(model_name, weights, model_paths, module_name, model_params):

try:
if weights:
model.load_state_dict(torch.load(weights, map_location='cpu'))
model.load_state_dict(torch.load(weights, map_location='cpu', weights_only=False))
except RuntimeError as err:
print('ERROR: Weights from {} cannot be loaded for model {}! Check matching between model and weights'.format(
weights, model_name))
Expand Down
Loading