Beispiel #1
0
    def add_layer(self, layer):

        # This implementation of ZeroPadding layers assumes symmetric single
        # padding ((1, 1), (1, 1)).
        # Todo: Generalize for asymmetric padding or arbitrary size.
        if 'ZeroPadding' in layer.__class__.__name__:
            # noinspection PyUnresolvedReferences
            padding = layer.padding
            if set(padding).issubset((1, (1, 1))):
                self.change_padding = True
                return
            else:
                raise NotImplementedError(
                    "Border_mode {} not supported.".format(padding))

        # Latest Keras versions need special permutation after Flatten layers.
        if 'Flatten' in layer.__class__.__name__ and \
                self.config.get('input', 'model_lib') == 'keras':
            self.flatten_shapes.append(
                (layer.name, get_shape_from_label(self.layers[-1].label)))
            return

        self.layers.append(
            self.sim.Population(np.prod(layer.output_shape[1:],
                                        dtype=np.int).item(),
                                self.sim.IF_curr_exp,
                                self.cellparams,
                                label=layer.name))

        self.layers[-1].initialize(v=self.layers[-1].get('v_rest'))
Beispiel #2
0
    def add_layer(self, layer):

        # Latest Keras versions need special permutation after Flatten layers.
        if 'Flatten' in layer.__class__.__name__ and \
                self.config.get('input', 'model_lib') == 'keras':
            self.flatten_shapes.append(
                (layer.name, get_shape_from_label(self.layers[-1].label)))
            return

        self.layers.append(
            self.sim.NeuronGroup(np.prod(layer.output_shape[1:]),
                                 model=self.eqs,
                                 method='linear',
                                 reset=self.v_reset,
                                 threshold=self.threshold,
                                 dt=self._dt * self.sim.ms))
        self.connections.append(
            self.sim.Synapses(self.layers[-2],
                              self.layers[-1],
                              'w:1',
                              on_pre='v+=w',
                              dt=self._dt * self.sim.ms))
        self.layers[-1].add_attribute('label')
        self.layers[-1].label = layer.name
        if 'spiketrains' in self._plot_keys \
                or 'spiketrains_n_b_l_t' in self._log_keys:
            self.spikemonitors.append(self.sim.SpikeMonitor(self.layers[-1]))
        if 'v_mem' in self._plot_keys or 'mem_n_b_l_t' in self._log_keys:
            self.statemonitors.append(
                self.sim.StateMonitor(self.layers[-1], 'v', True))
Beispiel #3
0
    def add_layer(self, layer):

        # Latest Keras versions need special permutation after Flatten layers.
        if 'Flatten' in layer.__class__.__name__ and \
                self.config.get('input', 'model_lib') == 'keras':
            self.flatten_shapes.append(
                (layer.name, get_shape_from_label(self.layers[-1].label)))
            return

        self.layers.append(
            self.sim.Population(np.prod(layer.output_shape[1:],
                                        dtype=np.int).item(),
                                self.sim.IF_curr_exp,
                                self.cellparams,
                                label=layer.name))

        self.layers[-1].initialize(v=self.layers[-1].get('v_rest'))
Beispiel #4
0
 def get_layer_shapes(self):
     from snntoolbox.simulation.utils import get_shape_from_label
     return [get_shape_from_label(label) if label not in ["InputLayer", "corr_pop"] else self.input_layer_shape for label in self.layer_names]