@@ -0,0 +1,1730 @@
+from keras.callbacks import CSVLogger%0A%0A%0Aclass RefCSVLogger(CSVLogger):%0A    %22%22%22Refined CSVLogger.%0A%0A    Also record results at arbitrary batches.%0A    %22%22%22%0A    def __init__(self, filename, separator=',', append=False, batch_epochs=%5B%5D):%0A        super().__init__(filename, separator=separator, append=append)%0A        self.batch_epochs = batch_epochs%0A        self.selected_epoch_batches = %5B%5D%0A%0A    def on_train_begin(self, logs=None):%0A        super().on_train_begin()%0A        self.batch_frac = self.params%5B'batch_size'%5D / self.params%5B'samples'%5D%0A        for batch_epoch in self.batch_epochs:%0A            epoch = int(batch_epoch)%0A            batch = round((batch_epoch - epoch) / self.batch_frac)%0A            self.selected_epoch_batches += %5B(epoch, batch)%5D%0A%0A    def on_epoch_begin(self, epoch, logs=None):%0A        self.epoch = epoch%0A        self.batch_logs_collection = %5B%5D%0A%0A    def on_batch_end(self, batch, logs=None):%0A        # Collect logs for selected batches.%0A        if (self.epoch, batch) in self.selected_epoch_batches:%0A            outputs = self.model.test_on_batch(*self.validation_data)%0A            metrics = self.params%5B'metrics'%5D%0A            # The latter half of metrics are supposed to be 'val_*'.%0A            metrics = metrics%5Blen(metrics) // 2:%5D%0A            test_logs = dict(zip(metrics, outputs))%0A            self.batch_logs_collection += %5B(batch, %7B**logs, **test_logs%7D)%5D%0A%0A    def on_epoch_end(self, epoch, logs=None):%0A        for batch, batch_logs in self.batch_logs_collection:%0A            batch_epoch = epoch - 1 + (batch + 1) * self.batch_frac%0A            batch_logs = %7Bk: batch_logs%5Bk%5D for k in logs.keys()%7D%0A            super().on_epoch_end(batch_epoch, logs=batch_logs)%0A        super().on_epoch_end(epoch, logs=logs)%0A

Add a refined CSVLogger