alibi_detect.models.tensorflow.resnet
Constants
BATCH_NORM_DECAY
BATCH_NORM_DECAYBATCH_NORM_DECAY: float = 0.997Convert a string or number to a floating point number, if possible.
BATCH_NORM_EPSILON
BATCH_NORM_EPSILONBATCH_NORM_EPSILON: float = 1e-05Convert a string or number to a floating point number, if possible.
L2_WEIGHT_DECAY
L2_WEIGHT_DECAYL2_WEIGHT_DECAY: float = 0.0002Convert a string or number to a floating point number, if possible.
LR_SCHEDULE
LR_SCHEDULELR_SCHEDULE: list = [(0.1, 91), (0.01, 136), (0.001, 182)]Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.
BASE_LEARNING_RATE
BASE_LEARNING_RATEBASE_LEARNING_RATE: float = 0.1Convert a string or number to a floating point number, if possible.
HEIGHT
HEIGHTHEIGHT: int = 32int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
int('0b100', base=0) 4
WIDTH
WIDTHWIDTH: int = 32int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
int('0b100', base=0) 4
NUM_CHANNELS
NUM_CHANNELSNUM_CHANNELS: int = 3int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer literal.
int('0b100', base=0) 4
LearningRateBatchScheduler
LearningRateBatchSchedulerInherits from: Callback
Constructor
LearningRateBatchScheduler(self, schedule: Callable, batch_size: int, steps_per_epoch: int)schedule
Callable
Function taking the epoch and batch index as input which returns the new learning rate as output.
batch_size
int
Batch size.
steps_per_epoch
int
Number of batches or steps per epoch.
Methods
on_batch_begin
on_batch_beginon_batch_begin(batch, logs = None)Executes before step begins.
batch
logs
None
on_epoch_begin
on_epoch_beginon_epoch_begin(epoch, logs = None)epoch
logs
None
Functions
conv_block
conv_blockconv_block(x_in: tensorflow.python.framework.tensor.Tensor, filters: Tuple[int, int], kernel_size: Union[int, list, Tuple[int]], stage: int, block: str, strides: Tuple[int, int] = (2, 2), l2_regularisation: bool = True) -> tensorflow.python.framework.tensor.TensorConv block in ResNet with a parameterised skip connection to reduce the width and height
controlled by the strides.
x_in
tensorflow.python.framework.tensor.Tensor
Input Tensor.
filters
Tuple[int, int]
Number of filters for each of the 2 conv layers.
kernel_size
Union[int, list, Tuple[int]]
Kernel size for the conv layers.
stage
int
Stage of the block in the ResNet.
block
str
Block within a stage in the ResNet.
strides
Tuple[int, int]
(2, 2)
Stride size applied to reduce the image size.
l2_regularisation
bool
True
Whether to apply L2 regularisation.
Returns
Type:
tensorflow.python.framework.tensor.Tensor
identity_block
identity_blockidentity_block(x_in: tensorflow.python.framework.tensor.Tensor, filters: Tuple[int, int], kernel_size: Union[int, list, Tuple[int]], stage: int, block: str, l2_regularisation: bool = True) -> tensorflow.python.framework.tensor.TensorIdentity block in ResNet.
x_in
tensorflow.python.framework.tensor.Tensor
Input Tensor.
filters
Tuple[int, int]
Number of filters for each of the 2 conv layers.
kernel_size
Union[int, list, Tuple[int]]
Kernel size for the conv layers.
stage
int
Stage of the block in the ResNet.
block
str
Block within a stage in the ResNet.
l2_regularisation
bool
True
Whether to apply L2 regularisation.
Returns
Type:
tensorflow.python.framework.tensor.Tensor
l2_regulariser
l2_regulariserl2_regulariser(l2_regularisation: bool = True)Apply L2 regularisation to kernel.
l2_regularisation
bool
True
Whether to apply L2 regularisation.
learning_rate_schedule
learning_rate_schedulelearning_rate_schedule(current_epoch: int, current_batch: int, batches_per_epoch: int, batch_size: int) -> floatLinear learning rate scaling and learning rate decay at specified epochs.
current_epoch
int
Current training epoch.
current_batch
int
Current batch with current epoch, not used.
batches_per_epoch
int
Number of batches or steps in an epoch, not used.
batch_size
int
Batch size.
Returns
Type:
float
preprocess_image
preprocess_imagepreprocess_image(x: numpy.ndarray, is_training: bool = True) -> numpy.ndarrayx
numpy.ndarray
is_training
bool
True
Returns
Type:
numpy.ndarray
resnet
resnetresnet(num_blocks: int, classes: int = 10, input_shape: Tuple[int, int, int] = (32, 32, 3)) -> keras.src.models.model.ModelDefine ResNet.
num_blocks
int
Number of ResNet blocks.
classes
int
10
Number of classification classes.
input_shape
Tuple[int, int, int]
(32, 32, 3)
Input shape of an image.
Returns
Type:
keras.src.models.model.Model
resnet_block
resnet_blockresnet_block(x_in: tensorflow.python.framework.tensor.Tensor, size: int, filters: Tuple[int, int], kernel_size: Union[int, list, Tuple[int]], stage: int, strides: Tuple[int, int] = (2, 2), l2_regularisation: bool = True) -> tensorflow.python.framework.tensor.TensorBlock in ResNet combining a conv block with identity blocks.
x_in
tensorflow.python.framework.tensor.Tensor
Input Tensor.
size
int
The ResNet block consists of 1 conv block and size-1 identity blocks.
filters
Tuple[int, int]
Number of filters for each of the conv layers.
kernel_size
Union[int, list, Tuple[int]]
Kernel size for the conv layers.
stage
int
Stage of the block in the ResNet.
strides
Tuple[int, int]
(2, 2)
Stride size applied to reduce the image size.
l2_regularisation
bool
True
Whether to apply L2 regularisation.
Returns
Type:
tensorflow.python.framework.tensor.Tensor
run
runrun(num_blocks: int, epochs: int, batch_size: int, model_dir: Union[str, os.PathLike], num_classes: int = 10, input_shape: Tuple[int, int, int] = (32, 32, 3), validation_freq: int = 10, verbose: int = 2, seed: int = 1, serving: bool = False) -> Nonenum_blocks
int
epochs
int
batch_size
int
model_dir
Union[str, os.PathLike]
num_classes
int
10
input_shape
Tuple[int, int, int]
(32, 32, 3)
validation_freq
int
10
verbose
int
2
seed
int
1
serving
bool
False
Returns
Type:
None
scale_by_instance
scale_by_instancescale_by_instance(x: numpy.ndarray, eps: float = 1e-12) -> numpy.ndarrayx
numpy.ndarray
eps
float
1e-12
Returns
Type:
numpy.ndarray
Last updated
Was this helpful?

