-
Notifications
You must be signed in to change notification settings - Fork 526
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
support converting models generated in v1.3 to 2.0 compatibility #725
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e20888d
add v1.3 compatibility
njzjz 40dd807
remove TestModelMajorCompatability as compatibility was added
njzjz 11fdd5c
Also remove TestModelMinorCompatability
njzjz a03b5ee
Update test_deeppot_a.py
njzjz ace77a8
Merge branch 'devel' into v1.3-compatibility
njzjz 1accc15
Revert "Update test_deeppot_a.py"
njzjz df3a94e
Revert "Also remove TestModelMinorCompatability"
njzjz 94f1d66
Revert "remove TestModelMajorCompatability as compatibility was added"
njzjz c8f9bf8
revert allowing 0.0 model
njzjz 139c264
convert from model 1.3 to 2.0
njzjz fc8b7f6
fix .gitignore
njzjz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from deepmd.utils.convert import convert_13_to_20 | ||
|
||
def convert( | ||
*, | ||
FROM: str, | ||
input_model: str, | ||
output_model: str, | ||
**kwargs, | ||
): | ||
if FROM == '1.3': | ||
convert_13_to_20(input_model, output_model) | ||
else: | ||
raise RuntimeError('unsupported model version ' + FROM) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
from deepmd.env import tf | ||
from google.protobuf import text_format | ||
from tensorflow.python.platform import gfile | ||
|
||
def convert_13_to_20(input_model: str, output_model: str): | ||
convert_pb_to_pbtxt(input_model, 'frozen_model.pbtxt') | ||
convert_dp13_to_dp20('frozen_model.pbtxt') | ||
convert_pbtxt_to_pb('frozen_model.pbtxt', output_model) | ||
if os.path.isfile('frozen_model.pbtxt'): | ||
os.remove('frozen_model.pbtxt') | ||
print("the converted output model (2.0 support) is saved in %s" % output_model) | ||
|
||
def convert_pb_to_pbtxt(pbfile: str, pbtxtfile: str): | ||
with gfile.FastGFile(pbfile, 'rb') as f: | ||
graph_def = tf.GraphDef() | ||
graph_def.ParseFromString(f.read()) | ||
tf.import_graph_def(graph_def, name='') | ||
tf.train.write_graph(graph_def, './', pbtxtfile, as_text=True) | ||
|
||
def convert_pbtxt_to_pb(pbtxtfile: str, pbfile: str): | ||
with tf.gfile.FastGFile(pbtxtfile, 'r') as f: | ||
graph_def = tf.GraphDef() | ||
file_content = f.read() | ||
# Merges the human-readable string in `file_content` into `graph_def`. | ||
text_format.Merge(file_content, graph_def) | ||
tf.train.write_graph(graph_def, './', pbfile, as_text=False) | ||
|
||
def convert_dp13_to_dp20(fname: str): | ||
with open(fname) as fp: | ||
file_content = fp.read() | ||
file_content += """ | ||
node { | ||
name: "model_attr/model_version" | ||
op: "Const" | ||
attr { | ||
key: "dtype" | ||
value { | ||
type: DT_STRING | ||
} | ||
} | ||
attr { | ||
key: "value" | ||
value { | ||
tensor { | ||
dtype: DT_STRING | ||
tensor_shape { | ||
} | ||
string_val: "1.0" | ||
} | ||
} | ||
} | ||
} | ||
""" | ||
file_content = file_content\ | ||
.replace('DescrptSeA', 'ProdEnvMatA')\ | ||
.replace('DescrptSeR', 'ProdEnvMatR') | ||
with open(fname, 'w') as fp: | ||
fp.write(file_content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to register
DescrptSeA
? the op name has changed toProdEnvMatA
byconvert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to load the old graph first when executing
convert
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see