def __init__(self, **kwargs): self.config = kwargs.pop(str('config'), None) if self.config is None: from snntoolbox.bin.utils import load_config # Todo: Enable loading config here. Needed when trying to load a # converted SNN from disk. For now we specify a dummy path. try: self.config = load_config('wdir/log/gui/test/.config') except FileNotFoundError: raise NotImplementedError self.layer_type = self.class_name self.dt = self.config.getfloat('simulation', 'dt') self.duration = self.config.getint('simulation', 'duration') self.tau_refrac = self.config.getfloat('cell', 'tau_refrac') self._v_thresh = self.config.getfloat('cell', 'v_thresh') self.v_thresh = None self.time = None self.mem = self.spiketrain = self.impulse = self.spikecounts = None self.mem_input = None # Used in MaxPooling layers self.refrac_until = self.max_spikerate = None if clamp_var: self.spikerate = self.var = None from snntoolbox.utils.utils import get_abs_path path, filename = \ get_abs_path(self.config.get('paths', 'filename_clamp_indices'), self.config) if filename != '': filepath = os.path.join(path, filename) assert os.path.isfile(filepath), \ "File with clamp indices not found at {}.".format(filepath) self.filename_clamp_indices = filepath self.clamp_idx = None self.payloads = None self.payloads_sum = None self.online_normalization = self.config.getboolean( 'normalization', 'online_normalization') allowed_kwargs = { 'input_shape', 'batch_input_shape', 'batch_size', 'dtype', 'name', 'trainable', 'weights', 'input_dtype', # legacy } for kwarg in kwargs.copy(): if kwarg not in allowed_kwargs: kwargs.pop(kwarg) Layer.__init__(self, **kwargs) self.stateful = True self._floatx = tf.keras.backend.floatx()
def __init__(self, **kwargs): self.config = kwargs.pop(str('config'), None) self.layer_type = self.class_name self.dt = self.config.getfloat('simulation', 'dt') self.duration = self.config.getint('simulation', 'duration') self.tau_refrac = self.config.getfloat('cell', 'tau_refrac') # if 'v_thresh' in kwargs: # self._v_thresh = kwargs['v_thresh'] # else: # self._v_thresh = self.config.getfloat('cell', 'v_thresh') self._v_thresh = self.config.getfloat('cell', 'v_thresh') self.v_thresh = None self.time = None self.mem = self.spiketrain = self.impulse = self.spikecounts = None self.refrac_until = self.max_spikerate = None if bias_relaxation: self.b0 = None if clamp_var: self.spikerate = self.var = None import os from snntoolbox.utils.utils import get_abs_path path, filename = \ get_abs_path(self.config.get('paths', 'filename_clamp_indices'), self.config) if filename != '': filepath = os.path.join(path, filename) assert os.path.isfile(filepath), \ "File with clamp indices not found at {}.".format(filepath) self.filename_clamp_indices = filepath self.clamp_idx = None self.payloads = self.config.getboolean('cell', 'payloads') self.payloads_sum = None self.online_normalization = self.config.getboolean( 'normalization', 'online_normalization') allowed_kwargs = {'input_shape', 'batch_input_shape', 'batch_size', 'dtype', 'name', 'trainable', 'weights', 'input_dtype', # legacy } for kwarg in kwargs.copy(): if kwarg not in allowed_kwargs: kwargs.pop(kwarg) Layer.__init__(self, **kwargs) self.stateful = True