Skip to content

Commit

Permalink
Add PyTorch test file (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
lutzroeder committed Jun 9, 2024
1 parent b2c185e commit cf094e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions source/pytorch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3591,7 +3591,7 @@ pytorch.Utility = class {
keys.splice(0, keys.length);
}
keys.push(...[
'state_dict', 'state_dict_stylepredictor', 'state_dict_ghiasi',
'state_dict', 'state_dicts', 'state_dict_stylepredictor', 'state_dict_ghiasi',
'state', 'model_state', 'model', 'model_state_dict', 'model_dict', 'net_dict',
'generator', 'discriminator', 'g_state', 'module', 'params',
'weight', 'weights', 'network_weights', 'network', 'net', 'netG', 'net_states',
Expand Down Expand Up @@ -3677,6 +3677,9 @@ pytorch.Utility = class {
};
const validate = (entries) => {
let count = 0;
if (entries instanceof Map === false && Object(entries) === entries) {
entries = new Map(Object.entries(entries));
}
if (entries && entries instanceof Map) {
entries.delete('_extra_state');
for (const [key, value] of entries) {
Expand Down Expand Up @@ -3745,7 +3748,11 @@ pytorch.Utility = class {
map.set('', flatten(obj));
} else if (Object(obj) === obj && Object.entries(obj).every(([, value]) => validate(value))) {
for (const [name, value] of Object.entries(obj)) {
map.set(name, value);
if (Object(value) === value) {
map.set(name, new Map(Object.entries(value)));
} else {
map.set(name, value);
}
}
} else if (Object(obj) === obj && Object.entries(obj).every(([, value]) => pytorch.Utility.isTensor(value))) {
map.set('', new Map(Object.entries(obj).map(([key, value]) => [key, value])));
Expand Down
7 changes: 7 additions & 0 deletions test/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -4896,6 +4896,13 @@
"format": "PyTorch v1.6",
"link": "https://github.com/lutzroeder/netron/issues/720"
},
{
"type": "pytorch",
"target": "cup_wild_vit_l_1img.ckpt",
"source": "https://github.com/user-attachments/files/15752923/cup_wild_vit_l_1img.ckpt.zip[cup_wild_vit_l_1img.ckpt]",
"format": "PyTorch v1.6",
"link": "https://github.com/lutzroeder/netron/issues/720"
},
{
"type": "pytorch",
"target": "data.pkl",
Expand Down

0 comments on commit cf094e2

Please sign in to comment.