qkeras.callbacks
Functions
|
Create a writer object with .as_default() context manager. |
|
Write a scalar under the active default writer. |
Classes
|
Schedules the gradual quantization noise training for each step (or epoch). |
- class qkeras.callbacks.QNoiseScheduler(start, finish, freq_type='epoch', update_freq=1, initial_step_or_epoch=0, exponent=3.0, use_ste=True, log_dir=None)[source]
Bases:
CallbackSchedules the gradual quantization noise training for each step (or epoch).
It updates the qnoise_factor in the quantizers to gradually introduce the quantization noise during training.
The idea was adopted from “https://arxiv.org/pdf/1903.01061.pdf”
- calculate_qnoise_factor(freq)[source]
Returns calculated qnoise_factor based on the current step (epoch) and the schedule parameters.
- Parameters:
freq – The current step (or epoch) to calculate the qnoise_factor.
- Returns:
calculated qnoise_factor.
- Return type:
- get_quantizers(model)[source]
Returns a list of quantizers with qnoise_factor in the model.
- Parameters:
model – model to get a list of quantizers with qnoise_factor.
- Returns:
A list of quantizers with the qnoise_factor variable.
- on_epoch_begin(epoch, logs=None)[source]
Called at the start of an epoch.
Subclasses should override for any actions to run. This function should only be called during TRAIN mode.
- Parameters:
epoch – Integer, index of epoch.
logs – Dict. Currently no data is passed to this argument for this method but that may change in the future.
- on_epoch_end(epoch, logs=None)[source]
Called at the end of an epoch.
Subclasses should override for any actions to run. This function should only be called during TRAIN mode.
- Parameters:
epoch – Integer, index of epoch.
logs – Dict, metric results for this training epoch, and for the validation epoch if validation is performed. Validation result keys are prefixed with val_. For training epoch, the values of the Model’s metrics are returned. Example: {‘loss’: 0.2, ‘accuracy’: 0.7}.
- on_train_batch_begin(batch, logs=None)[source]
Called at the beginning of a training batch in fit methods.
Subclasses should override for any actions to run.
Note that if the steps_per_execution argument to compile in Model is set to N, this method will only be called every N batches.
- Parameters:
batch – Integer, index of batch within the current epoch.
logs – Dict. Currently no data is passed to this argument for this method but that may change in the future.
- on_train_begin(logs=None)[source]
Called at the beginning of training.
Subclasses should override for any actions to run.
- Parameters:
logs – Dict. Currently no data is passed to this argument for this method but that may change in the future.
- set_qnoise_factor(quantizer, qnoise_factor)[source]
Set self.qnoise_factor and update the qnoise_factor of the quantizer.