if args.resume: model.optimizer = opt model.optimizer.optimize(model.layers_to_optimize, epoch=model.epoch_index) # run fprop again as a measure of the model state out_fprop = model.fprop(im) out_fprop_save2 = [x.get() for x in out_fprop] if not args.resume: save_obj([out_fprop_save, out_fprop_save2], 'serial_test_out1.pkl') else: # load up the saved file and compare run1 = load_obj('serial_test_out1.pkl') # compare the initial fprops for x, y in zip(run1[0], out_fprop_save): assert np.max(np.abs( x - y)) == 0.0, 'Deserialized model not matching serialized model' # and post extra training fprops for x, y in zip(run1[1], out_fprop_save2): if np.max(np.abs(x - y)) != 0.0: neon_logger.error('Max Diff: {}'.format(np.max(np.abs(x - y)))) raise ValueError( 'Deserialized training not matching serialized training') # see if the single epoch of optimization had any real effect for x, y in zip(out_fprop_save, out_fprop_save2): assert np.max(np.abs(x - y)) > 0.0, 'Training had no effect on model' neon_logger.display('passed')
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ---------------------------------------------------------------------------- import sys from neon import logger as neon_logger from neon.data.dataloaderadapter import DataLoaderAdapter try: from aeon import DataLoader as AeonLoader except ImportError: neon_logger.error('Unable to load Aeon data loading module.') neon_logger.error('Please follow installation instructions at:') neon_logger.error('https://github.com/NervanaSystems/aeon') sys.exit(1) def AeonDataLoader(config, adapter=True): if adapter: return DataLoaderAdapter(AeonLoader(config)) else: return AeonLoader(config)
""" Helper function to compare two serialized model files This is only comparing the model weights and states and layer config parameters Returns: bool: True if the two file match """ models = [] for fn in [file1, file2]: assert os.path.exists(fn), 'Could not find file %s' % fn with open(fn, 'r') as fid: models.append(ModelDescription(pickle.load(fid))) return models[0] == models[1] if __name__ == '__main__': parser = argparse.ArgumentParser(description='Compare two serialized model files.') parser.add_argument('file1') parser.add_argument('file2') args = parser.parse_args() if not compare_files(args.file1, args.file2): neon_logger.error('Models do not match!') sys.exit(1) else: neon_logger.display('Models match')
delta = model.cost.get_errors(im, l) model.bprop(delta) if args.resume: model.optimizer = opt model.optimizer.optimize(model.layers_to_optimize, epoch=model.epoch_index) # run fprop again as a measure of the model state out_fprop = model.fprop(im) out_fprop_save2 = [x.get() for x in out_fprop] if not args.resume: save_obj([out_fprop_save, out_fprop_save2], 'serial_test_out1.pkl') else: # load up the saved file and compare run1 = load_obj('serial_test_out1.pkl') # compare the initial fprops for x, y in zip(run1[0], out_fprop_save): assert np.max(np.abs(x - y)) == 0.0, 'Deserialized model not matching serialized model' # and post extra training fprops for x, y in zip(run1[1], out_fprop_save2): if np.max(np.abs(x - y)) != 0.0: neon_logger.error('Max Diff: {}'.format(np.max(np.abs(x - y)))) raise ValueError('Deserialized training not matching serialized training') # see if the single epoch of optimization had any real effect for x, y in zip(out_fprop_save, out_fprop_save2): assert np.max(np.abs(x - y)) > 0.0, 'Training had no effect on model' neon_logger.display('passed')
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ---------------------------------------------------------------------------- import sys from neon import logger as neon_logger from neon.data.dataloaderadapter import DataLoaderAdapter try: from aeon import DataLoader as AeonLoader except ImportError: neon_logger.error('Unable to load Aeon data loading module.') neon_logger.error('Please follow installation instructions at:') neon_logger.error('https://github.com/NervanaSystems/aeon') sys.exit(1) def AeonDataLoader(config, adapter=True): if adapter: return DataLoaderAdapter(AeonLoader(config)) else: return AeonLoader(config)
def __init__(self, *args, **kwargs): logger.error('DataIterator class has been deprecated and renamed' '"ArrayIterator" please use that name.') super(DataIterator, self).__init__(*args, **kwargs)