Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
model_parser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maximilian Xaver Tiefenbacher
model_parser
Commits
7a9d1696
Commit
7a9d1696
authored
Jan 18, 2021
by
Maximilian Xaver Tiefenbacher
Browse files
Options
Downloads
Patches
Plain Diff
Add new file
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
model_parser.py
+31
-0
31 additions, 0 deletions
model_parser.py
with
31 additions
and
0 deletions
model_parser.py
0 → 100644
+
31
−
0
View file @
7a9d1696
import
torch
import
sys
import
argparse
import
numpy
as
np
#This is just some setup for getting the name of the model if you excecute this file
parser
=
argparse
.
ArgumentParser
(
description
=
'
Get the name of the model
'
)
parser
.
add_argument
(
'
m_path
'
,
metavar
=
'
model_path
'
,
type
=
str
,
help
=
'
enter the name of the model
'
)
args
=
parser
.
parse_args
()
#The function looks for the model with the name given to it and returns every weight matrix as a numpy array
#if you already know which matrix you are interessted in you can give it to the function as a string and only this matrix will be returned
def
model_parser
(
path
,
layer
=
None
):
model
=
torch
.
load
(
path
,
map_location
=
torch
.
device
(
'
cpu
'
))
model_dict
=
model
.
state_dict
()
for
name
in
model_dict
:
model_dict
[
name
]
=
np
.
array
(
model_dict
[
name
])
if
layer
is
not
None
:
return
model_dict
[
layer
]
else
:
return
model_dict
if
__name__
==
"
__main__
"
:
x
=
model_parser
(
args
.
m_path
)
for
name
in
x
:
print
(
name
)
print
(
"
shape:
"
+
str
(
x
[
name
].
shape
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment