Skip to content

Commit

Permalink
Fixes and improvements:
Browse files Browse the repository at this point in the history
- Fixed LSA/FT (crashed under certain conditions)
- Fixed model_executer creation for TensorFlow models on ImageNet
- Removed unsused code and improved naming of variables
  • Loading branch information
phaase-hhi committed Nov 21, 2022
1 parent 9c44bed commit da45cfc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ source env/bin/activate

**Note**: For further information on how to set up a virtual python environment (also on **Windows**) refer to https://docs.python.org/3/library/venv.html .

When successfully installed, the software outputs the line : "Successfully installed NNC-0.1.0"
When successfully installed, the software outputs the line : "Successfully installed NNC-0.1.1"

### Importing the main module

Expand Down
3 changes: 3 additions & 0 deletions framework/pytorch_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,9 @@ def tune_model(
model_dict[module_name] = model_dict[module_name].reshape(base_model_arch[module_name].shape)
self.model.load_state_dict(model_dict)

for param in parameters:
parameters[param] = copy.deepcopy(self.model.state_dict()[param])

tuning_params = []
for name, param in self.model.named_parameters():
if lsa_flag and ft_flag and param_types[name] in nnc_core.nnr_model.O_TYPES:
Expand Down
19 changes: 0 additions & 19 deletions framework/tensorflow_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ def create_NNC_model_instance_from_object(
model_struct=None,
model_name=None
):

model_name = model_object.name

TEFModel = TensorFlowModel()
model_parameters, loaded_model_struct = TEFModel.init_model_from_model_object(model_object)
Expand Down Expand Up @@ -258,23 +256,6 @@ def load_model( self,
model_parameter_dict = {}
for name in layer_names:
model_parameter_dict[name] = model_file[name]

else:
if 'layer_names' in model_file.attrs:
module_names = [n.decode('utf8') for n in model_file.attrs['layer_names']]

layer_names = []
for mod_name in module_names:
layer = model_file[mod_name]
if 'weight_names' in layer.attrs:
weight_names = [mod_name+'/'+n.decode('utf8') for n in layer.attrs['weight_names']]
if weight_names:
layer_names += weight_names

model_parameter_dict = {}
for name in layer_names:
model_parameter_dict[name] = model_file[name]

except:
raise SystemExit("Can't read model: {}".format(model_path))

Expand Down
20 changes: 10 additions & 10 deletions framework/use_case_init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,36 +109,36 @@ def init_validation(self, dataset_path, batch_size, num_workers):
return val_set, val_loader

def init_test_tef(self, dataset_path, batch_size, num_workers, model_name):
val_set = self.dataset(
test_set = self.dataset(
root=dataset_path,
split='test'
)
self.__model_name = model_name

val_images, val_labels = zip(*val_set.imgs)
val_loader = tf.data.Dataset.from_tensor_slices((list(val_images), list(val_labels)))
val_loader = val_loader.map(lambda image, label: tf.py_function(self.preprocess,
test_images, test_labels = zip(*test_set.imgs)
test_loader = tf.data.Dataset.from_tensor_slices((list(test_images), list(test_labels)))
test_loader = test_loader.map(lambda image, label: tf.py_function(self.preprocess,
inp=[image, label],
Tout=[tf.float32, tf.int32]), num_parallel_calls=num_workers).batch(
batch_size)

return val_set, val_loader
return test_set, test_loader

def init_validation_tef(self, dataset_path, batch_size, num_workers, model_name):
test_set = self.dataset(
val_set = self.dataset(
root=dataset_path,
split='val'
)
self.__model_name = model_name

val_images, val_labels = zip(*test_set.imgs)
test_loader = tf.data.Dataset.from_tensor_slices((list(val_images), list(val_labels)))
test_loader = test_loader.map(lambda image, label: tf.py_function(self.preprocess,
val_images, val_labels = zip(*val_set.imgs)
val_loader = tf.data.Dataset.from_tensor_slices((list(val_images), list(val_labels)))
val_loader = val_loader.map(lambda image, label: tf.py_function(self.preprocess,
inp=[image, label],
Tout=[tf.float32, tf.int32]), num_parallel_calls=num_workers).batch(
batch_size)

return test_set, test_loader
return val_set, val_loader


def preprocess(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from setuptools.command.build_ext import build_ext
import setuptools

__version__ = '0.1.0'
__version__ = '0.1.1'


class get_pybind_include(object):
Expand Down

0 comments on commit da45cfc

Please sign in to comment.