Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
B
Basedformer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Basedformer
Commits
cff3389c
Commit
cff3389c
authored
Jun 17, 2022
by
Arda Cihaner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conversion script for resnet
parent
188c98ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
scripts/resnetport.py
scripts/resnetport.py
+32
-0
No files found.
scripts/resnetport.py
0 → 100644
View file @
cff3389c
import
os
from
typing
import
OrderedDict
import
torch
model_dir
=
'pretrained/resnet/'
new_state_dict
=
{}
weights
:
OrderedDict
=
torch
.
load
(
model_dir
+
'resnet_18.pth'
)
net_conf
=
(
False
,
(
2
,
2
,
2
,
2
))
counter
=
0
new_state_dict
[
'layerin.0.weight'
]
=
weights
[
'conv1.weight'
]
new_state_dict
[
'layerin.2.weight'
]
=
weights
[
'bn1.weight'
]
new_state_dict
[
'layerin.2.bias'
]
=
weights
[
'bn1.bias'
]
for
i
,
j
in
enumerate
(
net_conf
[
1
],
1
):
for
k
in
range
(
j
):
curr_layer
=
f
"layer{i}.{k}."
curr_state_dict_key
=
f
"resblocks.{counter}."
new_state_dict
[
curr_state_dict_key
+
"conv1.weight"
]
=
weights
[
curr_layer
+
"conv1.weight"
]
new_state_dict
[
curr_state_dict_key
+
"conv2.weight"
]
=
weights
[
curr_layer
+
"conv2.weight"
]
new_state_dict
[
curr_state_dict_key
+
"bn1.weight"
]
=
weights
[
curr_layer
+
"bn1.weight"
]
new_state_dict
[
curr_state_dict_key
+
"bn1.bias"
]
=
weights
[
curr_layer
+
"bn1.bias"
]
new_state_dict
[
curr_state_dict_key
+
"bn2.weight"
]
=
weights
[
curr_layer
+
"bn2.weight"
]
new_state_dict
[
curr_state_dict_key
+
"bn2.bias"
]
=
weights
[
curr_layer
+
"bn2.bias"
]
if
net_conf
[
0
]:
new_state_dict
[
curr_state_dict_key
+
"conv3.weight"
]
=
weights
[
curr_layer
+
"conv3.weight"
]
new_state_dict
[
curr_state_dict_key
+
"bn3.weight"
]
=
weights
[
curr_layer
+
"bn3.weight"
]
new_state_dict
[
curr_state_dict_key
+
"bn3.bias"
]
=
weights
[
curr_layer
+
"bn3.bias"
]
counter
+=
1
torch
.
save
(
new_state_dict
,
"pretrained/resnet/modified/resnet_18.pth"
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment