Skip to content

Commit

Permalink
Merge branch 'keras-team:main' into fix_torch_bincount
Browse files Browse the repository at this point in the history
  • Loading branch information
divyashreepathihalli authored Sep 20, 2023
2 parents 08d5979 + 0aa999b commit c763ab1
Show file tree
Hide file tree
Showing 43 changed files with 197 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_vectorize_layer(texts, vocab_size, max_seq, special_tokens=["[MASK]"]):
texts (list): List of string i.e input texts
vocab_size (int): vocab size
max_seq (int): Maximum sequence lenght.
special_tokens (list, optional): List of special tokens. Defaults to ['[MASK]'].
special_tokens (list, optional): List of special tokens. Defaults to `['[MASK]']`.
Returns:
layers.Layer: Return TextVectorization Keras Layer
Expand Down
16 changes: 8 additions & 8 deletions examples/keras_io/tensorflow/vision/shiftvit.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ class ShiftViTBlock(layers.Layer):
"""A unit ShiftViT Block
Args:
shift_pixel (int): The number of pixels to shift. Default to 1.
shift_pixel (int): The number of pixels to shift. Defaults to `1`.
mlp_expand_ratio (int): The ratio with which MLP features are
expanded. Default to 2.
expanded. Defaults to `2`.
mlp_dropout_rate (float): The dropout rate used in MLP.
num_div (int): The number of divisions of the feature map's channel.
Totally, 4/num_div of channels will be shifted. Defaults to 12.
Expand Down Expand Up @@ -493,10 +493,10 @@ class StackedShiftBlocks(layers.Layer):
stochastic_depth_rate (float): The maximum drop path rate chosen.
is_merge (boolean): A flag that determines the use of the Patch Merge
layer after the shift vit blocks.
num_div (int): The division of channels of the feature map. Defaults to 12.
shift_pixel (int): The number of pixels to shift. Defaults to 1.
num_div (int): The division of channels of the feature map. Defaults to `12`.
shift_pixel (int): The number of pixels to shift. Defaults to `1`.
mlp_expand_ratio (int): The ratio with which the initial dense layer of
the MLP is expanded Defaults to 2.
the MLP is expanded Defaults to `2`.
"""

def __init__(
Expand Down Expand Up @@ -578,10 +578,10 @@ class ShiftViTModel(keras.Model):
mlp_dropout_rate (float): The dropout rate used in the MLP block.
stochastic_depth_rate (float): The maximum drop rate probability.
num_div (int): The number of divisions of the channesl of the feature
map. Defaults to 12.
shift_pixel (int): The number of pixel to shift. Default to 1.
map. Defaults to `12`.
shift_pixel (int): The number of pixel to shift. Defaults to `1`.
mlp_expand_ratio (int): The ratio with which the initial mlp dense layer
is expanded to. Defaults to 2.
is expanded to. Defaults to `2`.
"""

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion keras_core/applications/efficientnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
classifier_activation: A `str` or callable. The activation function to use
on the "top" layer. Ignored unless `include_top=True`. Set
`classifier_activation=None` to return the logits of the "top" layer.
Defaults to 'softmax'.
Defaults to `'softmax'`.
When loading pretrained weights, `classifier_activation` can only
be `None` or `"softmax"`.
Expand Down
4 changes: 2 additions & 2 deletions keras_core/applications/imagenet_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
- torch: will scale pixels between 0 and 1 and then
will normalize each channel with respect to the
ImageNet dataset.
Defaults to "caffe".
Defaults to `"caffe"`.
"""

PREPROCESS_INPUT_DEFAULT_ERROR_DOC = """
Expand Down Expand Up @@ -119,7 +119,7 @@ def decode_predictions(preds, top=5):
Args:
preds: NumPy array encoding a batch of predictions.
top: Integer, how many top-guesses to return. Defaults to 5.
top: Integer, how many top-guesses to return. Defaults to `5`.
Returns:
A list of lists of top class prediction tuples
Expand Down
12 changes: 6 additions & 6 deletions keras_core/applications/resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def residual_block_v1(
Args:
x: Input tensor.
filters: No of filters in the bottleneck layer.
kernel_size: Kernel size of the bottleneck layer. Defaults to 3
stride: Stride of the first layer. Defaults to 1
kernel_size: Kernel size of the bottleneck layer. Defaults to `3`.
stride: Stride of the first layer. Defaults to `1`.
conv_shortcut: Use convolution shortcut if `True`, otherwise
use identity shortcut. Defaults to `True`
name(optional): Name of the block
Expand Down Expand Up @@ -278,7 +278,7 @@ def stack_residual_blocks_v1(x, filters, blocks, stride1=2, name=None):
x: Input tensor.
filters: Number of filters in the bottleneck layer in a block.
blocks: Number of blocks in the stacked blocks.
stride1: Stride of the first layer in the first block. Defaults to 2.
stride1: Stride of the first layer in the first block. Defaults to `2`.
name: Stack label.
Returns:
Expand All @@ -301,8 +301,8 @@ def residual_block_v2(
Args:
x: Input tensor.
filters: No of filters in the bottleneck layer.
kernel_size: Kernel size of the bottleneck layer. Defaults to 3
stride: Stride of the first layer. Defaults to 1
kernel_size: Kernel size of the bottleneck layer. Defaults to `3`.
stride: Stride of the first layer. Defaults to `1`.
conv_shortcut: Use convolution shortcut if `True`, otherwise
use identity shortcut. Defaults to `True`
name(optional): Name of the block
Expand Down Expand Up @@ -363,7 +363,7 @@ def stack_residual_blocks_v2(x, filters, blocks, stride1=2, name=None):
x: Input tensor.
filters: Number of filters in the bottleneck layer in a block.
blocks: Number of blocks in the stacked blocks.
stride1: Stride of the first layer in the first block. Defaults to 2.
stride1: Stride of the first layer in the first block. Defaults to `2`.
name: Stack label.
Returns:
Expand Down
6 changes: 3 additions & 3 deletions keras_core/backend/jax/distribution_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def list_devices(device_type=None):
Note that this should return the global devices in a distributed setting.
Args:
device_type: string of `"cpu"`, `"gpu"` or `"tpu"`. Default to `gpu` or
`tpu` if available when device_type is not provided. Otherwise
will return the `cpu` devices.
device_type: string of `"cpu"`, `"gpu"` or `"tpu"`. Defaults to `"gpu"`
or `"tpu"` if available when device_type is not provided. Otherwise
will return the `"cpu"` devices.
Return:
List of devices that are available for distribute computation.
Expand Down
15 changes: 7 additions & 8 deletions keras_core/backend/jax/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def resize(
"bilinear": 1,
}
AFFINE_TRANSFORM_FILL_MODES = {
"constant": "grid-constant",
"nearest": "nearest",
"wrap": "grid-wrap",
"mirror": "mirror",
"reflect": "reflect",
"constant",
"nearest",
"wrap",
"mirror",
"reflect",
}


Expand All @@ -80,11 +80,10 @@ def affine_transform(
f"{set(AFFINE_TRANSFORM_INTERPOLATIONS.keys())}. Received: "
f"interpolation={interpolation}"
)
if fill_mode not in AFFINE_TRANSFORM_FILL_MODES.keys():
if fill_mode not in AFFINE_TRANSFORM_FILL_MODES:
raise ValueError(
"Invalid value for argument `fill_mode`. Expected of one "
f"{set(AFFINE_TRANSFORM_FILL_MODES.keys())}. "
f"Received: fill_mode={fill_mode}"
f"{AFFINE_TRANSFORM_FILL_MODES}. Received: fill_mode={fill_mode}"
)

transform = convert_to_tensor(transform)
Expand Down
22 changes: 10 additions & 12 deletions keras_core/backend/numpy/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def resize(
"bilinear": 1,
}
AFFINE_TRANSFORM_FILL_MODES = {
"constant": "grid-constant",
"nearest": "nearest",
"wrap": "grid-wrap",
"mirror": "mirror",
"reflect": "reflect",
"constant",
"nearest",
"wrap",
"mirror",
"reflect",
}


Expand All @@ -79,11 +79,10 @@ def affine_transform(
f"{set(AFFINE_TRANSFORM_INTERPOLATIONS.keys())}. Received: "
f"interpolation={interpolation}"
)
if fill_mode not in AFFINE_TRANSFORM_FILL_MODES.keys():
if fill_mode not in AFFINE_TRANSFORM_FILL_MODES:
raise ValueError(
"Invalid value for argument `fill_mode`. Expected of one "
f"{set(AFFINE_TRANSFORM_FILL_MODES.keys())}. "
f"Received: fill_mode={fill_mode}"
f"{AFFINE_TRANSFORM_FILL_MODES}. Received: fill_mode={fill_mode}"
)

transform = convert_to_tensor(transform)
Expand Down Expand Up @@ -153,13 +152,12 @@ def affine_transform(
# apply affine transformation
affined = np.stack(
[
scipy.ndimage.map_coordinates(
map_coordinates(
image[i],
coordinates[i],
order=AFFINE_TRANSFORM_INTERPOLATIONS[interpolation],
mode=AFFINE_TRANSFORM_FILL_MODES[fill_mode],
cval=fill_value,
prefilter=False,
fill_mode=fill_mode,
fill_value=fill_value,
)
for i in range(batch_size)
],
Expand Down
4 changes: 2 additions & 2 deletions keras_core/distribution/distribution_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def list_devices(device_type=None):
Args:
device_type: string, one of `"cpu"`, `"gpu"` or `"tpu"`.
Default to `"gpu"` or `"tpu"` if available when
Defaults to `"gpu"` or `"tpu"` if available when
`device_type` is not provided. Otherwise
will return the `"cpu"` devices.
Expand Down Expand Up @@ -60,7 +60,7 @@ class DeviceMesh:
the rank of the `shape`. The `axis_names` will be used to
match/create the `TensorLayout` when distribute the data and
variables.
devices: Optional list of devices. Default to all the available
devices: Optional list of devices. Defaults to all the available
devices locally from `keras_core.distribution.list_devices()`.
"""

Expand Down
2 changes: 1 addition & 1 deletion keras_core/layers/activations/elu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ELU(Layer):
```
Args:
alpha: float, slope of negative section. Defaults to 1.0.
alpha: float, slope of negative section. Defaults to `1.0`.
**kwargs: Base layer keyword arguments, such as `name` and `dtype`.
"""

Expand Down
2 changes: 1 addition & 1 deletion keras_core/layers/activations/leaky_relu.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class LeakyReLU(Layer):
Args:
negative_slope: Float >= 0.0. Negative slope coefficient.
Defaults to 0.3.
Defaults to `0.3`.
**kwargs: Base layer keyword arguments, such as
`name` and `dtype`.
Expand Down
5 changes: 3 additions & 2 deletions keras_core/layers/activations/relu.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ class ReLU(Layer):
Args:
max_value: Float >= 0. Maximum activation value. None means unlimited.
Defaults to `None`.
negative_slope: Float >= 0. Negative slope coefficient. Defaults to 0.0.
negative_slope: Float >= 0. Negative slope coefficient.
Defaults to `0.0`.
threshold: Float >= 0. Threshold value for thresholded activation.
Defaults to 0.0.
Defaults to `0.0`.
**kwargs: Base layer keyword arguments, such as `name` and `dtype`.
"""

Expand Down
2 changes: 1 addition & 1 deletion keras_core/layers/attention/additive_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AdditiveAttention(Attention):
use_scale: If `True`, will create a scalar variable to scale the
attention scores.
dropout: Float between 0 and 1. Fraction of the units to drop for the
attention scores. Defaults to 0.0.
attention scores. Defaults to `0.0`.
Call Args:
inputs: List of the following tensors:
Expand Down
2 changes: 1 addition & 1 deletion keras_core/layers/attention/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Attention(Layer):
use_scale: If `True`, will create a scalar variable to scale the
attention scores.
dropout: Float between 0 and 1. Fraction of the units to drop for the
attention scores. Defaults to 0.0.
attention scores. Defaults to `0.0`.
score_mode: Function to use to compute attention scores, one of
`{"dot", "concat"}`. `"dot"` refers to the dot product between the
query and key vectors. `"concat"` refers to the hyperbolic tangent
Expand Down
2 changes: 1 addition & 1 deletion keras_core/layers/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Layer(BackendLayer, Operation):
dtype: The dtype of the layer's computations and weights. Can also be a
`keras_core.mixed_precision.DTypePolicy`,
which allows the computation and
weight dtype to differ. Default of `None` means to use
weight dtype to differ. Defaults to `None`. `None` means to use
`keras_core.mixed_precision.dtype_policy()`,
which is a `float32` policy unless set to different value
(via `keras_core.mixed_precision.set_dtype_policy()`).
Expand Down
2 changes: 1 addition & 1 deletion keras_core/layers/normalization/group_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GroupNormalization(Layer):
axis: Integer or List/Tuple. The axis or axes to normalize across.
Typically, this is the features axis/axes. The left-out axes are
typically the batch axis/axes. -1 is the last dimension in the
input. Defaults to -1.
input. Defaults to `-1`.
epsilon: Small float added to variance to avoid dividing by zero.
Defaults to 1e-3.
center: If `True`, add offset of `beta` to normalized tensor.
Expand Down
4 changes: 4 additions & 0 deletions keras_core/layers/preprocessing/discretization_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

import numpy as np
import pytest
from tensorflow import data as tf_data

from keras_core import backend
Expand Down Expand Up @@ -35,6 +36,9 @@ def test_adapt_flow(self):
output = layer(np.array([[0.0, 0.1, 0.3]]))
self.assertTrue(output.dtype, "int32")

@pytest.mark.skipif(
backend.backend() in ("torch", "numpy"), reason="TODO: fix me"
)
def test_correctness(self):
# int mode
layer = layers.Discretization(
Expand Down
4 changes: 2 additions & 2 deletions keras_core/layers/preprocessing/integer_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class IntegerLookup(IndexLookup):
If this value is more than 1, OOV inputs are modulated to
determine their OOV value.
If this value is 0, OOV inputs will cause an error when calling
the layer. Defaults to 1.
the layer. Defaults to `1`.
mask_token: An integer token that represents masked inputs. When
`output_mode` is `"int"`, the token is included in vocabulary
and mapped to index 0. In other output modes,
the token will not appear in the vocabulary and instances
of the mask token in the input will be dropped.
If set to None, no mask term will be added. Defaults to `None`.
oov_token: Only used when `invert` is `True`. The token to return
for OOV indices. Defaults to -1.
for OOV indices. Defaults to `-1`.
vocabulary: Optional. Either an array of integers or a string path to a
text file. If passing an array, can pass a tuple, list,
1D NumPy array, or 1D tensor containing the integer vocbulary terms.
Expand Down
2 changes: 1 addition & 1 deletion keras_core/layers/preprocessing/string_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class StringLookup(IndexLookup):
If this value is more than 1, OOV inputs are modulated to
determine their OOV value.
If this value is 0, OOV inputs will cause an error when calling
the layer. Defaults to 1.
the layer. Defaults to `1`.
mask_token: A token that represents masked inputs. When `output_mode` is
`"int"`, the token is included in vocabulary and mapped to index 0.
In other output modes, the token will not appear
Expand Down
4 changes: 2 additions & 2 deletions keras_core/layers/rnn/conv_lstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ConvLSTMCell(Layer, DropoutRNNCell):
`channels_first`. When unspecified, uses
`image_data_format` value found in your Keras config file at
`~/.keras/keras.json` (if exists) else 'channels_last'.
Defaults to 'channels_last'.
Defaults to `'channels_last'`.
dilation_rate: An integer or tuple/list of n integers, specifying the
dilation rate to use for dilated convolution.
Currently, specifying any `dilation_rate` value != 1 is
Expand Down Expand Up @@ -405,7 +405,7 @@ class ConvLSTM(RNN):
When unspecified, uses
`image_data_format` value found in your Keras config file at
`~/.keras/keras.json` (if exists) else 'channels_last'.
Defaults to 'channels_last'.
Defaults to `'channels_last'`.
dilation_rate: An integer or tuple/list of n integers, specifying
the dilation rate to use for dilated convolution.
Currently, specifying any `dilation_rate` value != 1 is
Expand Down
Loading

0 comments on commit c763ab1

Please sign in to comment.