Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SSD] script to convert weights to a pickled dict #436

Merged
merged 2 commits into from
May 12, 2021
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
32 changes: 32 additions & 0 deletions single_stage_detector/pth_to_pickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

from argparse import ArgumentParser
import pickle
import numpy as np
import torch

parser = ArgumentParser(description="Convert a pytorch (.pth) file to a pickled dictionary of numpy arrays. "
"The dictionary will have the following format: \n"
"{pytorch param name: numpy array}")
parser.add_argument('input_file', type=str, help='input pytorch .pth file')
parser.add_argument('output_file', type=str, help='output pickle file')
parser.add_argument('-v', '--verbose', action='store_true',
help='print parameters names and statistics')
args = parser.parse_args()

dict_out = {}
pth_input = torch.load(open(args.input_file, 'rb'))

for key, value in pth_input.items():
dict_out[key] = value.data.numpy()

if args.verbose:
print("name, dtype, mean, std, min, max")
for key, value in dict_out.items():
t_mean = np.mean(value)
t_std = np.std(value)
t_min = np.min(value)
t_max = np.max(value)
print(f"{key}, {value.dtype}, {value.shape}, {t_mean:0.3}, {t_std:0.3}, {t_min:0.3}, {t_max:0.3}")

pickle.dump(dict_out, open(args.output_file, 'wb'))
9 changes: 9 additions & 0 deletions single_stage_detector/ssd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,17 @@ cd reference/single_stage_detector/

Then use the downloaded file with `--pretrained-backbone <PATH TO WEIGHTS>` .

To read the weights without installing PyTorch, use the provided `pth_to_pickle.py` script to convert them to a pickled dictionary of numpy arrays:
```
cd reference/single_stage_detector/
python pth_to_pickle.py resnet34-333f7ec4.pth resnet34-333f7ec4.pickle
```

The pickled file can later be read with `pickle.load("resnet34-333f7ec4.pickle")`.

## Steps to run benchmark
tbd

## Steps to launch training
### NVIDIA DGX-1 (single GPU)
Launch configuration and system-specific hyperparameters for the NVIDIA DGX-1
Expand Down