This repository has been archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Get stats & original network def from "Download Model" button #891
Merged
+173
−61
Merged
Changes from all commits
Commits
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
|
||
# Constants | ||
CAFFE_SOLVER_FILE = 'solver.prototxt' | ||
CAFFE_ORIGINAL_FILE = 'original.prototxt' | ||
CAFFE_TRAIN_VAL_FILE = 'train_val.prototxt' | ||
CAFFE_SNAPSHOT_PREFIX = 'snapshot' | ||
CAFFE_DEPLOY_FILE = 'deploy.prototxt' | ||
|
@@ -83,11 +84,16 @@ def __init__(self, **kwargs): | |
self.solver = None | ||
|
||
self.solver_file = CAFFE_SOLVER_FILE | ||
self.original_file = CAFFE_ORIGINAL_FILE | ||
self.train_val_file = CAFFE_TRAIN_VAL_FILE | ||
self.snapshot_prefix = CAFFE_SNAPSHOT_PREFIX | ||
self.deploy_file = CAFFE_DEPLOY_FILE | ||
self.log_file = self.CAFFE_LOG | ||
|
||
self.digits_version = digits.__version__ | ||
self.caffe_version = config_value('caffe_root')['ver_str'] | ||
self.caffe_flavor = config_value('caffe_root')['flavor'] | ||
|
||
def __getstate__(self): | ||
state = super(CaffeTrainTask, self).__getstate__() | ||
|
||
|
@@ -228,6 +234,10 @@ def save_files_classification(self): | |
""" | ||
Save solver, train_val and deploy files to disk | ||
""" | ||
# Save the origin network to file: | ||
with open(self.path(self.original_file), 'w') as outfile: | ||
text_format.PrintMessage(self.network, outfile) | ||
|
||
network = cleanedUpClassificationNetwork(self.network, len(self.get_labels())) | ||
data_layers, train_val_layers, deploy_layers = filterLayersByState(network) | ||
|
||
|
@@ -523,6 +533,10 @@ def save_files_generic(self): | |
|
||
assert train_feature_db_path is not None, 'Training images are required' | ||
|
||
# Save the origin network to file: | ||
with open(self.path(self.original_file), 'w') as outfile: | ||
text_format.PrintMessage(self.network, outfile) | ||
|
||
### Split up train_val and deploy layers | ||
|
||
network = cleanedUpGenericNetwork(self.network) | ||
|
@@ -1030,6 +1044,41 @@ def after_runtime_error(self): | |
|
||
### TrainTask overrides | ||
|
||
@override | ||
def get_task_stats(self,epoch=-1): | ||
""" | ||
return a dictionary of task statistics | ||
""" | ||
|
||
loc, mean_file = os.path.split(self.dataset.get_mean_file()) | ||
|
||
stats = { | ||
"image dimensions": self.dataset.get_feature_dims(), | ||
"mean file": mean_file, | ||
"snapshot file": self.get_snapshot_filename(epoch), | ||
"solver file": self.solver_file, | ||
"train_val file": self.train_val_file, | ||
"deploy file": self.deploy_file, | ||
"framework": "caffe" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add "caffe_version" and "caffe_flavor" here? Or I guess "caffe version" and "caffe flavor" since you've gone with spaces. |
||
} | ||
|
||
# These attributes only available in more recent jobs: | ||
if hasattr(self,"original_file"): | ||
stats.update({ | ||
"caffe flavor": self.caffe_flavor, | ||
"caffe version": self.caffe_version, | ||
"network file": self.original_file, | ||
"digits version": self.digits_version | ||
}) | ||
|
||
if hasattr(self.dataset,"resize_mode"): | ||
stats.update({"image resize mode": self.dataset.resize_mode}) | ||
|
||
if hasattr(self.dataset,"labels_file"): | ||
stats.update({"labels file": self.dataset.labels_file}) | ||
|
||
return stats | ||
|
||
@override | ||
def detect_snapshots(self): | ||
self.snapshots = [] | ||
|
@@ -1316,18 +1365,7 @@ def get_net(self, epoch=None, gpu=-1): | |
if not self.has_model(): | ||
return False | ||
|
||
file_to_load = None | ||
|
||
if not epoch: | ||
epoch = self.snapshots[-1][1] | ||
file_to_load = self.snapshots[-1][0] | ||
else: | ||
for snapshot_file, snapshot_epoch in self.snapshots: | ||
if snapshot_epoch == epoch: | ||
file_to_load = snapshot_file | ||
break | ||
if file_to_load is None: | ||
raise Exception('snapshot not found for epoch "%s"' % epoch) | ||
file_to_load = self.get_snapshot(epoch) | ||
|
||
# check if already loaded | ||
if self.loaded_snapshot_file and self.loaded_snapshot_file == file_to_load \ | ||
|
@@ -1421,11 +1459,14 @@ def get_model_files(self): | |
""" | ||
return paths to model files | ||
""" | ||
return { | ||
model_files = { | ||
"Solver": self.solver_file, | ||
"Network (train/val)": self.train_val_file, | ||
"Network (deploy)": self.deploy_file | ||
} | ||
if hasattr(self,"original_file"): | ||
model_files.update({"Network (original)": self.original_file}) | ||
return model_files | ||
|
||
@override | ||
def get_network_desc(self): | ||
|
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 |
---|---|---|
|
@@ -64,6 +64,8 @@ def __init__(self, **kwargs): | |
self.snapshot_prefix = TORCH_SNAPSHOT_PREFIX | ||
self.log_file = self.TORCH_LOG | ||
|
||
self.digits_version = digits.__version__ | ||
|
||
def __getstate__(self): | ||
state = super(TorchTrainTask, self).__getstate__() | ||
|
||
|
@@ -926,23 +928,29 @@ def get_network_desc(self): | |
desc = infile.read() | ||
return desc | ||
|
||
def get_snapshot(self, epoch): | ||
@override | ||
def get_task_stats(self,epoch=-1): | ||
""" | ||
return snapshot file for specified epoch | ||
return a dictionary of task statistics | ||
""" | ||
file_to_load = None | ||
|
||
if not epoch: | ||
epoch = self.snapshots[-1][1] | ||
file_to_load = self.snapshots[-1][0] | ||
else: | ||
for snapshot_file, snapshot_epoch in self.snapshots: | ||
if snapshot_epoch == epoch: | ||
file_to_load = snapshot_file | ||
break | ||
if file_to_load is None: | ||
raise Exception('snapshot not found for epoch "%s"' % epoch) | ||
loc, mean_file = os.path.split(self.dataset.get_mean_file()) | ||
|
||
stats = { | ||
"image dimensions": self.dataset.get_feature_dims(), | ||
"mean file": mean_file, | ||
"snapshot file": self.get_snapshot_filename(epoch), | ||
"model file": self.model_file, | ||
"framework": "torch" | ||
} | ||
|
||
if hasattr(self,"digits_version"): | ||
stats.update({"digits version": self.digits_version}) | ||
|
||
return file_to_load | ||
if hasattr(self.dataset,"resize_mode"): | ||
stats.update({"image resize mode": self.dataset.resize_mode}) | ||
|
||
if hasattr(self.dataset,"labels_file"): | ||
stats.update({"labels file": self.dataset.labels_file}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A very picky reviewer might argue that this method looks for the most part like the |
||
|
||
return stats |
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
Oops, something went wrong.
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.
nice!