(self, callback_data, model)
Called when training is about to end

        Arguments:
            callback_data (HDF5 dataset): shared data between callbacks
            model (Model): model object
Called when training is about to end
Called when training is about to end
def on_train_end(self, callback_data, model):
        """
        Called when training is about to end

        Arguments:
            callback_data (HDF5 dataset): shared data between callbacks
            model (Model): model object
        """
        # TODO: generalize for more complex topologies
        layers = model.layers.layers
        self.raw_img_cache = dict()
        self.raw_img_key = dict()
        C, H, W = layers[0].in_shape
        msg = "{} Visualization of {} feature maps per layer:"
        logger.info(msg.format(self.name, self.max_fm))

        for l, lyr in enumerate(layers):
            if isinstance(lyr, Convolution):
                K = lyr.convparams['K']
                num_fm = min(K, self.max_fm)

                lyr_data = callback_data.create_group("deconv/max_act/{0:04}".format(l))
                lyr_data.create_dataset("batch_img", (num_fm, 2), dtype='uint16')
                lyr_data.create_dataset("fm_loc", (num_fm, 1), dtype='int16')
                lyr_data.create_dataset("vis", (num_fm, H, W, C), dtype='uint8')
                lyr_data.create_dataset("activation", (num_fm, 1), dtype='float32')
                lyr_data['activation'][:] = -float('Inf')

        self.valid_set.reset()
        t_start = time.time()
        num_sampled_batches = int(self.dataset_pct / 100. *
                                  self.valid_set.nbatches + 0.5)
        for batch_ind, (x, t) in enumerate(self.valid_set, 0):

            if batch_ind > num_sampled_batches:
                break

            imgs_to_store = self.get_layer_acts(callback_data, model, x, batch_ind)

            self.store_images(callback_data, batch_ind, imgs_to_store, x, C, H, W)

            self._progress_update("Find Max Act Imgs", batch_ind,
                                  num_sampled_batches, "batches",
                                  time.time() - t_start)

        sys.stdout.write("\n")

        # Loop over every layer to visualize
        t_start = time.time()
        for i in range(1, len(layers) + 1):
            layer_ind = len(layers) - i

            if isinstance(layers[layer_ind], Convolution):
                num_fm, act_h, act_w = layers[layer_ind].out_shape
                act_size = act_h * act_w
                self.visualize_layer(callback_data, model, num_fm, act_size, layer_ind)
            self._progress_update("Compute " + self.name, i,
                                  len(layers), "layers",
                                  time.time() - t_start)

        sys.stdout.write("\n")
def on_train_end ( self , callback_data , model ) : # TODO: generalize for more complex topologies layers = model . layers . layers self . raw_img_cache = dict ( ) self . raw_img_key = dict ( ) C , H , W = layers [ 0 ] . in_shape msg = "{} Visualization of {} feature maps per layer:" logger . info ( msg . format ( self . name , self . max_fm ) ) for l , lyr in enumerate ( layers ) : if isinstance ( lyr , Convolution ) : K = lyr . convparams [ 'K' ] num_fm = min ( K , self . max_fm ) lyr_data = callback_data . create_group ( "deconv/max_act/{0:04}" . format ( l ) ) lyr_data . create_dataset ( "batch_img" , ( num_fm , 2 ) , dtype = 'uint16' ) lyr_data . create_dataset ( "fm_loc" , ( num_fm , 1 ) , dtype = 'int16' ) lyr_data . create_dataset ( "vis" , ( num_fm , H , W , C ) , dtype = 'uint8' ) lyr_data . create_dataset ( "activation" , ( num_fm , 1 ) , dtype = 'float32' ) lyr_data [ 'activation' ] [ : ] = - float ( 'Inf' ) self . valid_set . reset ( ) t_start = time . time ( ) num_sampled_batches = int ( self . dataset_pct / 100. * self . valid_set . nbatches + 0.5 ) for batch_ind , ( x , t ) in enumerate ( self . valid_set , 0 ) : if batch_ind > num_sampled_batches : break imgs_to_store = self . get_layer_acts ( callback_data , model , x , batch_ind ) self . store_images ( callback_data , batch_ind , imgs_to_store , x , C , H , W ) self . _progress_update ( "Find Max Act Imgs" , batch_ind , num_sampled_batches , "batches" , time . time ( ) - t_start ) sys . stdout . write ( "\n" ) # Loop over every layer to visualize t_start = time . time ( ) for i in range ( 1 , len ( layers ) + 1 ) : layer_ind = len ( layers ) - i if isinstance ( layers [ layer_ind ] , Convolution ) : num_fm , act_h , act_w = layers [ layer_ind ] . out_shape act_size = act_h * act_w self . visualize_layer ( callback_data , model , num_fm , act_size , layer_ind ) self . _progress_update ( "Compute " + self . name , i , len ( layers ) , "layers" , time . time ( ) - t_start ) sys . stdout . write ( "\n" )