本文整理汇总了Python中neon.callbacks.callbacks.Callbacks.load_callbacks方法的典型用法代码示例。如果您正苦于以下问题:Python Callbacks.load_callbacks方法的具体用法?Python Callbacks.load_callbacks怎么用?Python Callbacks.load_callbacks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neon.callbacks.callbacks.Callbacks
的用法示例。
在下文中一共展示了Callbacks.load_callbacks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deserialize
# 需要导入模块: from neon.callbacks.callbacks import Callbacks [as 别名]
# 或者: from neon.callbacks.callbacks.Callbacks import load_callbacks [as 别名]
def deserialize(fn, datasets=None, inference=False):
"""
Helper function to load all objects from a serialized file,
this includes callbacks and datasets as well as the model, layers,
etc.
Arguments:
datasets (DataSet, optional): If the dataset is not serialized
in the file it can be passed in
as an argument. This will also
override any dataset in the serialized
file
inference (bool, optional): if true only the weights will be loaded, not
the states
Returns:
Model: the model object
Dataset: the data set object
Callback: the callbacks
"""
config_dict = load_obj(fn)
if datasets is not None:
logger.warn('Ignoring datasets serialized in archive file %s' % fn)
elif 'datasets' in config_dict:
ds_cls = load_class(config_dict['datasets']['type'])
dataset = ds_cls.gen_class(config_dict['datasets']['config'])
datasets = dataset.gen_iterators()
if 'train' in datasets:
data_iter = datasets['train']
else:
key = datasets.keys()[0]
data_iter = datasets[key]
logger.warn('Could not find training set iterator'
'using %s instead' % key)
model = Model(config_dict, data_iter)
callbacks = None
if 'callbacks' in config_dict:
# run through the callbacks looking for dataset objects
# replace them with the corresponding data set above
cbs = config_dict['callbacks']['callbacks']
for cb in cbs:
if 'config' not in cb:
cb['config'] = {}
for arg in cb['config']:
if type(cb['config'][arg]) is dict and 'type' in cb['config'][arg]:
if cb['config'][arg]['type'] == 'Data':
key = cb['config'][arg]['name']
if key in datasets:
cb['config'][arg] = datasets[key]
else:
cb['config'][arg] = None
# now we can generate the callbacks
callbacks = Callbacks.load_callbacks(config_dict['callbacks'], model)
return (model, dataset, callbacks)