Bins the given values for use in a histogram.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.histogram_fixed_width_bins
Given the tensor values, this operation returns a rank 1 Tensor representing the indices of a histogram into which each element of values would be binned. The bins are equal width and determined by the arguments value_range and nbins.


Return a Tensor with the same shape and contents as input.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.identity
The return value is not the same Tensor as the original, but contains the same values. This operation is fast when used on the same device.
Calling tf.identity on a variable will make a Tensor that represents the value of that variable at the time it is called. This is equivalent to calling <variable>.read_value().


Returns a list of tensors with the same shapes and contents as the input
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.identity_n
tensors.
This op can be used to override the gradient for complicated functions. For example, suppose y = f(x) and we wish to apply a custom function g for backprop such that dx = g(dy). In Python,


Image ops.
The tf.image module contains various functions for image processing and decoding-encoding Ops.
Many of the encoding/decoding functions are also available in the core tf.io module.
The resizing Ops accept input images as tensors of several types. They always output resized images as float32 tensors.
The convenience function tf.image.resize supports both 4-D and 3-D tensors as input and output. 4-D tensors are for batches of images, 3-D tensors for individual images.
Resized images will be distorted if their original aspect ratio is not the same as size. To avoid distortions see tf.image.resize_with_pad.
The Class tf.image.ResizeMethod provides various resize methods like bilinear, nearest_neighbor.
Image ops work either on individual images or on batches of images, depending on the shape of their input Tensor.
If 3-D, the shape is [height, width, channels], and the Tensor represents one image. If 4-D, the shape is [batch_size, height, width, channels], and the Tensor represents batch_size images.
Currently, channels can usefully be 1, 2, 3, or 4. Single-channel images are grayscale, images with 3 channels are encoded as either RGB or HSV. Images with 2 or 4 channels include an alpha channel, which has to be stripped from the image before passing the image to most image processing functions (and can be re-attached later).
Internally, images are either stored in as one float32 per channel per pixel (implicitly, values are assumed to lie in [0,1)) or one uint8 per channel per pixel (values are assumed to lie in [0,255]).
TensorFlow can convert between images in RGB or HSV or YIQ.
TensorFlow provides functions to adjust images in various ways: brightness, contrast, hue, and saturation. Each adjustment can be done with predefined parameters or with random parameters picked from predefined intervals. Random adjustments are often useful to expand a training set and reduce overfitting.
If several adjustments are chained it is advisable to minimize the number of redundant conversions by first converting the images to the most natural data type and representation.
TensorFlow provides Ops to decode and encode JPEG and PNG formats. Encoded images are represented by scalar string Tensors, decoded images by 3-D uint8 tensors of shape [height, width, channels]. (PNG also supports uint16.)
The encode and decode Ops apply to one image at a time. Their input and output are all of variable size. If you need fixed size images, pass the output of the decode Ops to one of the cropping and resizing Ops.
class ResizeMethod: See tf.image.resize for details.
adjust_brightness(...): Adjust the brightness of RGB or Grayscale images.
adjust_contrast(...): Adjust contrast of RGB or grayscale images.
adjust_gamma(...): Performs Gamma Correction.
adjust_hue(...): Adjust hue of RGB images.
adjust_jpeg_quality(...): Adjust jpeg encoding quality of an image.
adjust_saturation(...): Adjust saturation of RGB images.
central_crop(...): Crop the central region of the image(s).
combined_non_max_suppression(...): Greedily selects a subset of bounding boxes in descending order of score.
convert_image_dtype(...): Convert image to dtype, scaling its values if needed.
crop_and_resize(...): Extracts crops from the input image tensor and resizes them.
crop_to_bounding_box(...): Crops an image to a specified bounding box.
decode_and_crop_jpeg(...): Decode and Crop a JPEG-encoded image to a uint8 tensor.
decode_bmp(...): Decode the first frame of a BMP-encoded image to a uint8 tensor.
decode_gif(...): Decode the frame(s) of a GIF-encoded image to a uint8 tensor.
decode_image(...): Function for decode_bmp, decode_gif, decode_jpeg, and decode_png.
decode_jpeg(...): Decode a JPEG-encoded image to a uint8 tensor.
decode_png(...): Decode a PNG-encoded image to a uint8 or uint16 tensor.
draw_bounding_boxes(...): Draw bounding boxes on a batch of images.
encode_jpeg(...): JPEG-encode an image.
encode_png(...): PNG-encode an image.
extract_glimpse(...): Extracts a glimpse from the input tensor.
extract_jpeg_shape(...): Extract the shape information of a JPEG-encoded image.
extract_patches(...): Extract patches from images.
flip_left_right(...): Flip an image horizontally (left to right).
flip_up_down(...): Flip an image vertically (upside down).
generate_bounding_box_proposals(...): Generate bounding box proposals from encoded bounding boxes.
grayscale_to_rgb(...): Converts one or more images from Grayscale to RGB.
hsv_to_rgb(...): Convert one or more images from HSV to RGB.
image_gradients(...): Returns image gradients (dy, dx) for each color channel.
is_jpeg(...): Convenience function to check if the 'contents' encodes a JPEG image.
non_max_suppression(...): Greedily selects a subset of bounding boxes in descending order of score.
non_max_suppression_overlaps(...): Greedily selects a subset of bounding boxes in descending order of score.
non_max_suppression_padded(...): Greedily selects a subset of bounding boxes in descending order of score.
non_max_suppression_with_scores(...): Greedily selects a subset of bounding boxes in descending order of score.
pad_to_bounding_box(...): Pad image with zeros to the specified height and width.
per_image_standardization(...): Linearly scales each image in image to have mean 0 and variance 1.
psnr(...): Returns the Peak Signal-to-Noise Ratio between a and b.
random_brightness(...): Adjust the brightness of images by a random factor.
random_contrast(...): Adjust the contrast of an image or images by a random factor.
random_crop(...): Randomly crops a tensor to a given size.
random_flip_left_right(...): Randomly flip an image horizontally (left to right).
random_flip_up_down(...): Randomly flips an image vertically (upside down).
random_hue(...): Adjust the hue of RGB images by a random factor.
random_jpeg_quality(...): Randomly changes jpeg encoding quality for inducing jpeg noise.
random_saturation(...): Adjust the saturation of RGB images by a random factor.
resize(...): Resize images to size using the specified method.
resize_with_crop_or_pad(...): Crops and/or pads an image to a target width and height.
resize_with_pad(...): Resizes and pads an image to a target width and height.
rgb_to_grayscale(...): Converts one or more images from RGB to Grayscale.
rgb_to_hsv(...): Converts one or more images from RGB to HSV.
rgb_to_yiq(...): Converts one or more images from RGB to YIQ.
rgb_to_yuv(...): Converts one or more images from RGB to YUV.
rot90(...): Rotate image(s) counter-clockwise by 90 degrees.
sample_distorted_bounding_box(...): Generate a single randomly distorted bounding box for an image.
sobel_edges(...): Returns a tensor holding Sobel edge maps.
ssim(...): Computes SSIM index between img1 and img2.
ssim_multiscale(...): Computes the MS-SSIM between img1 and img2.
stateless_random_brightness(...): Adjust the brightness of images by a random factor deterministically.
stateless_random_contrast(...): Adjust the contrast of images by a random factor deterministically.
stateless_random_crop(...): Randomly crops a tensor to a given size in a deterministic manner.
stateless_random_flip_left_right(...): Randomly flip an image horizontally (left to right) deterministically.
stateless_random_flip_up_down(...): Randomly flip an image vertically (upside down) deterministically.
stateless_random_hue(...): Adjust the hue of RGB images by a random factor deterministically.
stateless_random_jpeg_quality(...): Deterministically radomize jpeg encoding quality for inducing jpeg noise.
stateless_random_saturation(...): Adjust the saturation of RGB images by a random factor deterministically.
stateless_sample_distorted_bounding_box(...): Generate a randomly distorted bounding box for an image deterministically.
total_variation(...): Calculate and return the total variation for one or more images.
transpose(...): Transpose image(s) by swapping the height and width dimension.
yiq_to_rgb(...): Converts one or more images from YIQ to RGB.
yuv_to_rgb(...): Converts one or more images from YUV to RGB.


Adjust the brightness of RGB or Grayscale images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.adjust_brightness
This is a convenience method that converts RGB images to float representation, adjusts their brightness, and then converts them back to the original data type. If several adjustments are chained, it is advisable to minimize the number of redundant conversions.
The value delta is added to all components of the tensor image. image is converted to float and scaled appropriately if it is in fixed-point representation, and delta is converted to the same data type. For regular images, delta should be in the range (-1,1), as it is added to the image in floating point representation, where pixel values are in the [0,1) range.


Adjust contrast of RGB or grayscale images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.adjust_contrast
This is a convenience method that converts RGB images to float representation, adjusts their contrast, and then converts them back to the original data type. If several adjustments are chained, it is advisable to minimize the number of redundant conversions.
images is a tensor of at least 3 dimensions. The last 3 dimensions are interpreted as [height, width, channels]. The other dimensions only represent a collection of images, such as [batch, height, width, channels].
Contrast is adjusted independently for each channel of each image.
For each channel, this Op computes the mean of the image pixels in the channel and then adjusts each component x of each pixel to (x - mean) * contrast_factor + mean.


Performs Gamma Correction.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.adjust_gamma
on the input image.
Also known as Power Law Transform. This function converts the input images at first to float representation, then transforms them pixelwise according to the equation Out = gain * In**gamma, and then converts the back to the original data type.
For gamma greater than 1, the histogram will shift towards left and the output image will be darker than the input image. For gamma less than 1, the histogram will shift towards right and the output image will be brighter than the input image.
Wikipedia


Adjust hue of RGB images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.adjust_hue
This is a convenience method that converts an RGB image to float representation, converts it to HSV, adds an offset to the hue channel, converts back to RGB and then back to the original data type. If several adjustments are chained it is advisable to minimize the number of redundant conversions.
image is an RGB image. The image hue is adjusted by converting the image(s) to HSV and rotating the hue channel (H) by delta. The image is then converted back to RGB.
delta must be in the interval [-1, 1].


Adjust jpeg encoding quality of an image.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.adjust_jpeg_quality
This is a convenience method that converts an image to uint8 representation, encodes it to jpeg with jpeg_quality, decodes it, and then converts back to the original data type.
jpeg_quality must be in the interval [0, 100].


Adjust saturation of RGB images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.adjust_saturation
This is a convenience method that converts RGB images to float representation, converts them to HSV, adds an offset to the saturation channel, converts back to RGB and then back to the original data type. If several adjustments are chained it is advisable to minimize the number of redundant conversions.
image is an RGB image or images. The image saturation is adjusted by converting the images to HSV and multiplying the saturation (S) channel by saturation_factor and clipping. The images are then converted back to RGB.


Crop the central region of the image(s).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.central_crop
Remove the outer parts of an image but retain the central region of the image along each dimension. If we specify central_fraction = 0.5, this function returns the region marked with "X" in the below diagram.
This function works on either a single image (image is a 3-D Tensor), or a batch of images (image is a 4-D Tensor).


Greedily selects a subset of bounding boxes in descending order of score.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.combined_non_max_suppression
This operation performs non_max_suppression on the inputs per batch, across all classes. Prunes away boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. Bounding boxes are supplied as [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any diagonal pair of box corners and the coordinates can be provided as normalized (i.e., lying in the interval [0, 1]) or absolute. Note that this algorithm is agnostic to where the origin is in the coordinate system. Also note that this algorithm is invariant to orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system result in the same boxes being selected by the algorithm. The output of this operation is the final boxes, scores and classes tensor returned after performing non_max_suppression.


Convert image to dtype, scaling its values if needed.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.convert_image_dtype
Images that are represented using floating point values are expected to have values in the range [0,1). Image data stored in integer data types are expected to have values in the range [0,MAX], where MAX is the largest positive representable number for the data type.
This op converts between data types, scaling the values appropriately before casting.
Note that converting from floating point inputs to integer types may lead to over/underflow problems. Set saturate to True to avoid such problem in problematic conversions. If enabled, saturation will clip the output into the allowed range before performing a potentially dangerous cast (and only before performing such a cast, i.e., when casting from a floating point to an integer type, and when casting from a signed to an unsigned type; saturate has no effect on casts between floats, or on casts that increase the type's range).


Extracts crops from the input image tensor and resizes them.
Extracts crops from the input image tensor and resizes them using bilinear sampling or nearest neighbor sampling (possibly with aspect ratio change) to a common output size specified by crop_size. This is more general than the crop_to_bounding_box op which extracts a fixed size slice from the input image and does not allow resizing or aspect ratio change.
Returns a tensor with crops from the input image at positions defined at the bounding box locations in boxes. The cropped boxes are all resized (with bilinear or nearest neighbor interpolation) to a fixed size = [crop_height, crop_width]. The result is a 4-D tensor [num_boxes, crop_height, crop_width, depth]. The resizing is corner aligned. In particular, if boxes = [[0, 0, 1, 1]], the method will give identical results to using tf.compat.v1.image.resize_bilinear() or tf.compat.v1.image.resize_nearest_neighbor()(depends on the method argument) with align_corners=True.


Crops an image to a specified bounding box.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.crop_to_bounding_box
This op cuts a rectangular part out of image. The top-left corner of the returned image is at offset_height, offset_width in image, and its lower-right corner is at offset_height + target_height, offset_width + target_width.


Draw bounding boxes on a batch of images.
Outputs a copy of images but draws on top of the pixels zero or more bounding boxes specified by the locations in boxes. The coordinates of the each bounding box in boxes are encoded as [y_min, x_min, y_max, x_max]. The bounding box coordinates are floats in [0.0, 1.0] relative to the width and the height of the underlying image.
For example, if an image is 100 x 200 pixels (height x width) and the bounding box is [0.1, 0.2, 0.5, 0.9], the upper-left and bottom-right coordinates of the bounding box will be (40, 10) to (180, 50) (in (x,y) coordinates).
Parts of the bounding box may fall outside the image.


Extracts a glimpse from the input tensor.
Returns a set of windows called glimpses extracted at location offsets from the input tensor. If the windows only partially overlaps the inputs, the non-overlapping areas will be filled with random noise.
The result is a 4-D tensor of shape [batch_size, glimpse_height, glimpse_width, channels]. The channels and batch dimensions are the same as that of the input tensor. The height and width of the output windows are specified in the size parameter.
The argument normalized and centered controls how the windows are built:


Extract patches from images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.extract_patches
This op collects patches from the input image, as if applying a convolution. All extracted patches are stacked in the depth (last) dimension of the output.
Specifically, the op extracts patches of shape sizes which are strides apart in the input image. The output is subsampled using the rates argument, in the same manner as "atrous" or "dilated" convolutions.
The result is a 4D tensor which is indexed by batch, row, and column. output[i, x, y] contains a flattened patch of size sizes[1], sizes[2] which is taken from the input starting at images[i, x*strides[1], y*strides[2]].
Each output patch can be reshaped to sizes[1], sizes[2], depth, where depth is images.shape[3].
The output elements are taken from the input at intervals given by the rate argument, as in dilated convolutions.
The padding argument has no effect on the size of each patch, it determines how many patches are extracted. If VALID, only patches which are fully contained in the input image are included. If SAME, all patches whose starting point is inside the input are included, and areas outside the input default to zero.
If we mark the pixels in the input image which are taken for the output with *, we see the pattern:
We can again draw the effect, this time using the symbols *, x, + and o to distinguish the patches:


Flip an image horizontally (left to right).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.flip_left_right
Outputs the contents of image flipped along the width dimension.
See also tf.reverse.


Flip an image vertically (upside down).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.flip_up_down
Outputs the contents of image flipped along the height dimension.
See also reverse().


Generate bounding box proposals from encoded bounding boxes.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.generate_bounding_box_proposals


Converts one or more images from Grayscale to RGB.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.grayscale_to_rgb
Outputs a tensor of the same DType and rank as images. The size of the last dimension of the output is 3, containing the RGB value of the pixels. The input images' last dimension must be size 1.


Convert one or more images from HSV to RGB.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.hsv_to_rgb
Outputs a tensor of the same shape as the images tensor, containing the RGB value of the pixels. The output is only well defined if the value in images are in [0,1].
See rgb_to_hsv for a description of the HSV encoding.


Returns image gradients (dy, dx) for each color channel.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.image_gradients
Both output tensors have the same shape as the input: [batch_size, h, w, d]. The gradient values are organized so that [I(x+1, y) - I(x, y)] is in location (x, y). That means that dy will always have zeros in the last row, and dx will always have zeros in the last column.


Greedily selects a subset of bounding boxes in descending order of score.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.non_max_suppression
Prunes away boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. Bounding boxes are supplied as [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any diagonal pair of box corners and the coordinates can be provided as normalized (i.e., lying in the interval [0, 1]) or absolute. Note that this algorithm is agnostic to where the origin is in the coordinate system. Note that this algorithm is invariant to orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system result in the same boxes being selected by the algorithm. The output of this operation is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. The bounding box coordinates corresponding to the selected indices can then be obtained using the tf.gather operation. For example:


Greedily selects a subset of bounding boxes in descending order of score.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.non_max_suppression_overlaps
Prunes away boxes that have high overlap with previously selected boxes. N-by-n overlap values are supplied as square matrix. The output of this operation is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. The bounding box coordinates corresponding to the selected indices can then be obtained using the tf.gather operation. For example:


Greedily selects a subset of bounding boxes in descending order of score.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.non_max_suppression_padded
Performs algorithmically equivalent operation to tf.image.non_max_suppression, with the addition of an optional parameter which zero-pads the output to be of size max_output_size. The output of this operation is a tuple containing the set of integers indexing into the input collection of bounding boxes representing the selected boxes and the number of valid indices in the index set. The bounding box coordinates corresponding to the selected indices can then be obtained using the tf.slice and tf.gather operations. For example: ```python selected_indices_padded, num_valid = tf.image.non_max_suppression_padded( boxes, scores, max_output_size, iou_threshold, score_threshold, pad_to_max_output_size=True) selected_indices = tf.slice( selected_indices_padded, tf.constant([0]), num_valid) selected_boxes = tf.gather(boxes, selected_indices)


Greedily selects a subset of bounding boxes in descending order of score.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.non_max_suppression_with_scores
Prunes away boxes that have high intersection-over-union (IOU) overlap with previously selected boxes. Bounding boxes are supplied as [y1, x1, y2, x2], where (y1, x1) and (y2, x2) are the coordinates of any diagonal pair of box corners and the coordinates can be provided as normalized (i.e., lying in the interval [0, 1]) or absolute. Note that this algorithm is agnostic to where the origin is in the coordinate system. Note that this algorithm is invariant to orthogonal transformations and translations of the coordinate system; thus translating or reflections of the coordinate system result in the same boxes being selected by the algorithm. The output of this operation is a set of integers indexing into the input collection of bounding boxes representing the selected boxes. The bounding box coordinates corresponding to the selected indices can then be obtained using the tf.gather operation. For example:
This function generalizes the tf.image.non_max_suppression op by also supporting a Soft-NMS (with Gaussian weighting) mode (c.f. Bodla et al, https://arxiv.org/abs/1704.04503) where boxes reduce the score of other overlapping boxes instead of directly causing them to be pruned. Consequently, in contrast to tf.image.non_max_suppression, tf.image.non_max_suppression_padded returns the new scores of each input box in the second output, selected_scores.
To enable this Soft-NMS mode, set the soft_nms_sigma parameter to be larger than 0. When soft_nms_sigma equals 0, the behavior of tf.image.non_max_suppression_padded is identical to that of tf.image.non_max_suppression (except for the extra output) both in function and in running time.


Pad image with zeros to the specified height and width.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.pad_to_bounding_box
Adds offset_height rows of zeros on top, offset_width columns of zeros on the left, and then pads the image on the bottom and right with zeros until it has dimensions target_height, target_width.
This op does nothing if offset_* is zero and the image already has size target_height by target_width.


Linearly scales each image in image to have mean 0 and variance 1.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.per_image_standardization
For each 3-D image x in image, computes (x - mean) / adjusted_stddev, where


Returns the Peak Signal-to-Noise Ratio between a and b.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.psnr
This is intended to be used on signals (or images). Produces a PSNR value for each image in batch.
The last three dimensions of input are expected to be [height, width, depth].


Adjust the brightness of images by a random factor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.random_brightness
Equivalent to adjust_brightness() using a delta randomly picked in the interval [-max_delta, max_delta).


Adjust the contrast of an image or images by a random factor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.random_contrast
Equivalent to adjust_contrast() but uses a contrast_factor randomly picked in the interval [lower, upper).


Randomly crops a tensor to a given size.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.random_crop, tf.compat.v1.random_crop
Slices a shape size portion out of value at a uniformly chosen offset. Requires value.shape >= size.
If a dimension should not be cropped, pass the full size of that dimension. For example, RGB images can be cropped with size = [crop_height, crop_width, 3].


Randomly flip an image horizontally (left to right).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.random_flip_left_right
With a 1 in 2 chance, outputs the contents of image flipped along the second dimension, which is width. Otherwise output the image as-is. When passing a batch of images, each image will be randomly flipped independent of other images.
Randomly flip multiple images.


Randomly flips an image vertically (upside down).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.random_flip_up_down
With a 1 in 2 chance, outputs the contents of image flipped along the first dimension, which is height. Otherwise, output the image as-is. When passing a batch of images, each image will be randomly flipped independent of other images.
Randomly flip multiple images.


Adjust the hue of RGB images by a random factor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.random_hue
Equivalent to adjust_hue() but uses a delta randomly picked in the interval [-max_delta, max_delta).
max_delta must be in the interval [0, 0.5].


Randomly changes jpeg encoding quality for inducing jpeg noise.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.random_jpeg_quality
min_jpeg_quality must be in the interval [0, 100] and less than max_jpeg_quality. max_jpeg_quality must be in the interval [0, 100].


Adjust the saturation of RGB images by a random factor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.random_saturation
Equivalent to adjust_saturation() but uses a saturation_factor randomly picked in the interval [lower, upper).


Resize images to size using the specified method.
Resized images will be distorted if their original aspect ratio is not the same as size. To avoid distortions see tf.image.resize_with_pad.
It works equally well with a single image instead of a batch of images:
When antialias is true, the sampling filter will anti-alias the input image as well as interpolate. When downsampling an image with anti-aliasing the sampling filter kernel is scaled in order to properly anti-alias the input image signal. antialias has no effect when upsampling an image:
The method argument expects an item from the image.ResizeMethod enum, or the string equivalent. The options are:
The return value has type float32, unless the method is ResizeMethod.NEAREST_NEIGHBOR, then the return dtype is the dtype of images:
With preserve_aspect_ratio=True, the aspect ratio is preserved, so size is the maximum for each dimension:


Crops and/or pads an image to a target width and height.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.resize_image_with_crop_or_pad, tf.compat.v1.image.resize_with_crop_or_pad
Resizes an image to a target width and height by either centrally cropping the image or padding it evenly with zeros.
If width or height is greater than the specified target_width or target_height respectively, this op centrally crops along that dimension. If width or height is smaller than the specified target_width or target_height respectively, this op centrally pads with 0 along that dimension.


Resizes and pads an image to a target width and height.
Resizes an image to a target width and height by keeping the aspect ratio the same without distortion. If the target dimensions don't match the image dimensions, the image is resized and then padded with zeroes to match requested dimensions.


Converts one or more images from RGB to Grayscale.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.rgb_to_grayscale
Outputs a tensor of the same DType and rank as images. The size of the last dimension of the output is 1, containing the Grayscale value of the pixels.


Converts one or more images from RGB to HSV.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.rgb_to_hsv
Outputs a tensor of the same shape as the images tensor, containing the HSV value of the pixels. The output is only well defined if the value in images are in [0,1].
output[..., 0] contains hue, output[..., 1] contains saturation, and output[..., 2] contains value. All HSV values are in [0,1]. A hue of 0 corresponds to pure red, hue 1/3 is pure green, and 2/3 is pure blue.


Converts one or more images from RGB to YIQ.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.rgb_to_yiq
Outputs a tensor of the same shape as the images tensor, containing the YIQ value of the pixels. The output is only well defined if the value in images are in [0,1].


Converts one or more images from RGB to YUV.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.rgb_to_yuv
Outputs a tensor of the same shape as the images tensor, containing the YUV value of the pixels. The output is only well defined if the value in images are in [0, 1]. There are two ways of representing an image: [0, 255] pixel values range or 0, 1 pixel values range. Users need to convert the input image into a float [0, 1] range.


Rotate image(s) counter-clockwise by 90 degrees.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.rot90


Generate a single randomly distorted bounding box for an image.
Bounding box annotations are often supplied in addition to ground-truth labels in image recognition or object localization tasks. A common technique for training such a system is to randomly distort an image while preserving its content, i.e. data augmentation. This Op outputs a randomly distorted localization of an object, i.e. bounding box, given an image_size, bounding_boxes and a series of constraints.
The output of this Op is a single bounding box that may be used to crop the original image. The output is returned as 3 tensors: begin, size and bboxes. The first 2 tensors can be fed directly into tf.slice to crop the image. The latter may be supplied to tf.image.draw_bounding_boxes to visualize what the bounding box looks like.
Bounding boxes are supplied and returned as [y_min, x_min, y_max, x_max]. The bounding box coordinates are floats in [0.0, 1.0] relative to the width and the height of the underlying image.
For example,
Note that if no bounding box information is available, setting use_image_if_no_bounding_boxes = true will assume there is a single implicit bounding box covering the whole image. If use_image_if_no_bounding_boxes is false and no bounding boxes are supplied, an error is raised.


Returns a tensor holding Sobel edge maps.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.sobel_edges


Computes SSIM index between img1 and img2.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.ssim
This function is based on the standard SSIM implementation from: Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: from error visibility to structural similarity. IEEE transactions on image processing.
The image sizes must be at least 11x11 because of the filter size.


Computes the MS-SSIM between img1 and img2.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.ssim_multiscale
This function assumes that img1 and img2 are image batches, i.e. the last three dimensions are [height, width, channels].
Original paper: Wang, Zhou, Eero P. Simoncelli, and Alan C. Bovik. "Multiscale structural similarity for image quality assessment." Signals, Systems and Computers, 2004.


Adjust the brightness of images by a random factor deterministically.
Equivalent to adjust_brightness() using a delta randomly picked in the interval [-max_delta, max_delta).
Guarantees the same results given the same seed independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed).


Adjust the contrast of images by a random factor deterministically.
Guarantees the same results given the same seed independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed).


Randomly crops a tensor to a given size in a deterministic manner.
Slices a shape size portion out of value at a uniformly chosen offset. Requires value.shape >= size.
If a dimension should not be cropped, pass the full size of that dimension. For example, RGB images can be cropped with size = [crop_height, crop_width, 3].
Guarantees the same results given the same seed independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed).


Randomly flip an image horizontally (left to right) deterministically.
Guarantees the same results given the same seed independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed).


Randomly flip an image vertically (upside down) deterministically.
Guarantees the same results given the same seed independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed).


Adjust the hue of RGB images by a random factor deterministically.
Equivalent to adjust_hue() but uses a delta randomly picked in the interval [-max_delta, max_delta).
Guarantees the same results given the same seed independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed).
max_delta must be in the interval [0, 0.5].


Deterministically radomize jpeg encoding quality for inducing jpeg noise.
Guarantees the same results given the same seed independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed).
min_jpeg_quality must be in the interval [0, 100] and less than max_jpeg_quality. max_jpeg_quality must be in the interval [0, 100].


Adjust the saturation of RGB images by a random factor deterministically.
Equivalent to adjust_saturation() but uses a saturation_factor randomly picked in the interval [lower, upper).
Guarantees the same results given the same seed independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed).


Generate a randomly distorted bounding box for an image deterministically.
Bounding box annotations are often supplied in addition to ground-truth labels in image recognition or object localization tasks. A common technique for training such a system is to randomly distort an image while preserving its content, i.e. data augmentation. This Op, given the same seed, deterministically outputs a randomly distorted localization of an object, i.e. bounding box, given an image_size, bounding_boxes and a series of constraints.
The output of this Op is a single bounding box that may be used to crop the original image. The output is returned as 3 tensors: begin, size and bboxes. The first 2 tensors can be fed directly into tf.slice to crop the image. The latter may be supplied to tf.image.draw_bounding_boxes to visualize what the bounding box looks like.
Bounding boxes are supplied and returned as [y_min, x_min, y_max, x_max]. The bounding box coordinates are floats in [0.0, 1.0] relative to the width and the height of the underlying image.
The output of this Op is guaranteed to be the same given the same seed and is independent of how many times the function is called, and independent of global seed settings (e.g. tf.random.set_seed).
Note that if no bounding box information is available, setting use_image_if_no_bounding_boxes = true will assume there is a single implicit bounding box covering the whole image. If use_image_if_no_bounding_boxes is false and no bounding boxes are supplied, an error is raised.


Calculate and return the total variation for one or more images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.total_variation
The total variation is the sum of the absolute differences for neighboring pixel-values in the input images. This measures how much noise is in the images.
This can be used as a loss-function during optimization so as to suppress noise in images. If you have a batch of images, then you should calculate the scalar loss-value as the sum: loss = tf.reduce_sum(tf.image.total_variation(images))
This implements the anisotropic 2-D version of the formula described here:
https://en.wikipedia.org/wiki/Total_variation_denoising
If images was 4-D, return a 1-D float Tensor of shape [batch] with the total variation for each image in the batch. If images was 3-D, return a scalar float with the total variation for that image.


Transpose image(s) by swapping the height and width dimension.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.transpose, tf.compat.v1.image.transpose_image


Converts one or more images from YIQ to RGB.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.yiq_to_rgb
Outputs a tensor of the same shape as the images tensor, containing the RGB value of the pixels. The output is only well defined if the Y value in images are in [0,1], I value are in [-0.5957,0.5957] and Q value are in [-0.5226,0.5226].


Converts one or more images from YUV to RGB.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.image.yuv_to_rgb
Outputs a tensor of the same shape as the images tensor, containing the RGB value of the pixels. The output is only well defined if the Y value in images are in [0,1], U and V value are in [-0.5,0.5].
As per the above description, you need to scale your YUV images if their pixel values are not in the required range. Below given example illustrates preprocessing of each channel of images before feeding them to yuv_to_rgb.


A sparse representation of a set of tensor slices at given indices.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.IndexedSlices
This class is a simple wrapper for a pair of Tensor objects:
An IndexedSlices is typically used to represent a subset of a larger tensor dense of shape [LARGE0, D1, .. , DN] where LARGE0 >> D0. The values in indices are the indices in the first dimension of the slices that have been extracted from the larger tensor.
The dense tensor dense represented by an IndexedSlices slices has
The IndexedSlices class is used principally in the definition of gradients for operations that have sparse gradients (e.g. tf.gather).
Contrast this representation with tf.sparse.SparseTensor, which uses multi-dimensional indices and scalar values.
View source
View source


Type specification for a tf.IndexedSlices.
Inherits From: TypeSpec
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.IndexedSlicesSpec
View source
Returns true if spec_or_value is compatible with this TypeSpec.
View source
Returns the most specific TypeSpec compatible with self and other.
View source
Return self==value.
View source
Return self!=value.


A context manager that lifts ops out of control-flow scopes and function-building graphs.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.init_scope
There is often a need to lift variable initialization ops out of control-flow scopes, function-building graphs, and gradient tapes. Entering an init_scope is a mechanism for satisfying these desiderata. In particular, entering an init_scope has three effects:
(1) All control dependencies are cleared the moment the scope is entered; this is equivalent to entering the context manager returned from control_dependencies(None), which has the side-effect of exiting control-flow scopes like tf.cond and tf.while_loop.
(2) All operations that are created while the scope is active are lifted into the lowest context on the context_stack that is not building a graph function. Here, a context is defined as either a graph or an eager context. Every context switch, i.e., every installation of a graph as the default graph and every switch into eager mode, is logged in a thread-local stack called context_switches; the log entry for a context switch is popped from the stack when the context is exited. Entering an init_scope is equivalent to crawling up context_switches, finding the first context that is not building a graph function, and entering it. A caveat is that if graph mode is enabled but the default graph stack is empty, then entering an init_scope will simply install a fresh graph as the default one.
(3) The gradient tape is paused while the scope is active.
When eager execution is enabled, code inside an init_scope block runs with eager execution enabled even when tracing a tf.function. For example:


Indicates whether the caller code is executing inside a tf.function.


Public API for tf.io namespace.
gfile module: Public API for tf.io.gfile namespace.
class FixedLenFeature: Configuration for parsing a fixed-length input feature.
class FixedLenSequenceFeature: Configuration for parsing a variable-length input feature into a Tensor.
class RaggedFeature: Configuration for passing a RaggedTensor input feature.
class SparseFeature: Configuration for parsing a sparse input feature from an Example.
class TFRecordOptions: Options used for manipulating TFRecord files.
class TFRecordWriter: A class to write records to a TFRecords file.
class VarLenFeature: Configuration for parsing a variable-length input feature.
decode_and_crop_jpeg(...): Decode and Crop a JPEG-encoded image to a uint8 tensor.
decode_base64(...): Decode web-safe base64-encoded strings.
decode_bmp(...): Decode the first frame of a BMP-encoded image to a uint8 tensor.
decode_compressed(...): Decompress strings.
decode_csv(...): Convert CSV records to tensors. Each column maps to one tensor.
decode_gif(...): Decode the frame(s) of a GIF-encoded image to a uint8 tensor.
decode_image(...): Function for decode_bmp, decode_gif, decode_jpeg, and decode_png.
decode_jpeg(...): Decode a JPEG-encoded image to a uint8 tensor.
decode_json_example(...): Convert JSON-encoded Example records to binary protocol buffer strings.
decode_png(...): Decode a PNG-encoded image to a uint8 or uint16 tensor.
decode_proto(...): The op extracts fields from a serialized protocol buffers message into tensors.
decode_raw(...): Convert raw byte strings into tensors.
deserialize_many_sparse(...): Deserialize and concatenate SparseTensors from a serialized minibatch.
encode_base64(...): Encode strings into web-safe base64 format.
encode_jpeg(...): JPEG-encode an image.
encode_png(...): PNG-encode an image.
encode_proto(...): The op serializes protobuf messages provided in the input tensors.
extract_jpeg_shape(...): Extract the shape information of a JPEG-encoded image.
is_jpeg(...): Convenience function to check if the 'contents' encodes a JPEG image.
match_filenames_once(...): Save the list of files matching pattern, so it is only computed once.
matching_files(...): Returns the set of files matching one or more glob patterns.
parse_example(...): Parses Example protos into a dict of tensors.
parse_sequence_example(...): Parses a batch of SequenceExample protos.
parse_single_example(...): Parses a single Example proto.
parse_single_sequence_example(...): Parses a single SequenceExample proto.
parse_tensor(...): Transforms a serialized tensorflow.TensorProto proto into a Tensor.
read_file(...): Reads and outputs the entire contents of the input filename.
serialize_many_sparse(...): Serialize N-minibatch SparseTensor into an [N, 3] Tensor.
serialize_sparse(...): Serialize a SparseTensor into a 3-vector (1-D Tensor) object.
serialize_tensor(...): Transforms a Tensor into a serialized TensorProto proto.
write_file(...): Writes contents to the file at input filename. Creates file and recursively
write_graph(...): Writes a graph proto to a file.


Decode and Crop a JPEG-encoded image to a uint8 tensor.
Main aliases
tf.image.decode_and_crop_jpeg
See Migration guide for more details.
tf.compat.v1.image.decode_and_crop_jpeg, tf.compat.v1.io.decode_and_crop_jpeg
The attr channels indicates the desired number of color channels for the decoded image.
If needed, the JPEG-encoded image is transformed to match the requested number of color channels.
The attr ratio allows downscaling the image by an integer factor during decoding. Allowed values are: 1, 2, 4, and 8. This is much faster than downscaling the image later.
It is equivalent to a combination of decode and crop, but much faster by only decoding partial jpeg image.


Decode web-safe base64-encoded strings.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.decode_base64, tf.compat.v1.io.decode_base64
Input may or may not have padding at the end. See EncodeBase64 for padding. Web-safe means that input must use - and _ instead of + and /.


Decode the first frame of a BMP-encoded image to a uint8 tensor.
Main aliases
tf.image.decode_bmp
See Migration guide for more details.
tf.compat.v1.image.decode_bmp, tf.compat.v1.io.decode_bmp
The attr channels indicates the desired number of color channels for the decoded image.


Decompress strings.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.decode_compressed, tf.compat.v1.io.decode_compressed
This op decompresses each element of the bytes input Tensor, which is assumed to be compressed using the given compression_type.
The output is a string Tensor of the same shape as bytes, each element containing the decompressed data from the corresponding element in bytes.


Convert CSV records to tensors. Each column maps to one tensor.
RFC 4180 format is expected for the CSV records. (https://tools.ietf.org/html/rfc4180) Note that we allow leading and trailing spaces with int or float field.


Decode the frame(s) of a GIF-encoded image to a uint8 tensor.
Main aliases
tf.image.decode_gif
See Migration guide for more details.
tf.compat.v1.image.decode_gif, tf.compat.v1.io.decode_gif
GIF images with frame or transparency compression are not supported. On Linux and MacOS systems, convert animated GIFs from compressed to uncompressed by running:
This op also supports decoding JPEGs and PNGs, though it is cleaner to use tf.io.decode_image.


Function for decode_bmp, decode_gif, decode_jpeg, and decode_png.
Main aliases
tf.image.decode_image
See Migration guide for more details.
tf.compat.v1.image.decode_image, tf.compat.v1.io.decode_image
Detects whether an image is a BMP, GIF, JPEG, or PNG, and performs the appropriate operation to convert the input bytes string into a Tensor of type dtype.


Decode a JPEG-encoded image to a uint8 tensor.
Main aliases
tf.image.decode_jpeg
See Migration guide for more details.
tf.compat.v1.image.decode_jpeg, tf.compat.v1.io.decode_jpeg
The attr channels indicates the desired number of color channels for the decoded image.
If needed, the JPEG-encoded image is transformed to match the requested number of color channels.
The attr ratio allows downscaling the image by an integer factor during decoding. Allowed values are: 1, 2, 4, and 8. This is much faster than downscaling the image later.
This op also supports decoding PNGs and non-animated GIFs since the interface is the same, though it is cleaner to use tf.io.decode_image.


Convert JSON-encoded Example records to binary protocol buffer strings.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.decode_json_example, tf.compat.v1.io.decode_json_example
This op translates a tensor containing Example records, encoded using the standard JSON mapping, into a tensor containing the same records encoded as binary protocol buffers. The resulting tensor can then be fed to any of the other Example-parsing ops.


Decode a PNG-encoded image to a uint8 or uint16 tensor.
Main aliases
tf.image.decode_png
See Migration guide for more details.
tf.compat.v1.image.decode_png, tf.compat.v1.io.decode_png
The attr channels indicates the desired number of color channels for the decoded image.
If needed, the PNG-encoded image is transformed to match the requested number of color channels.
This op also supports decoding JPEGs and non-animated GIFs since the interface is the same, though it is cleaner to use tf.io.decode_image.


The op extracts fields from a serialized protocol buffers message into tensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.decode_proto
The decode_proto op extracts fields from a serialized protocol buffers message into tensors. The fields in field_names are decoded and converted to the corresponding output_types if possible.
A message_type name must be provided to give context for the field names. The actual message descriptor can be looked up either in the linked-in descriptor pool or a filename provided by the caller using the descriptor_source attribute.
Each output tensor is a dense tensor. This means that it is padded to hold the largest number of repeated elements seen in the input minibatch. (The shape is also padded by one to prevent zero-sized dimensions). The actual repeat counts for each example in the minibatch can be found in the sizes output. In many cases the output of decode_proto is fed immediately into tf.squeeze if missing values are not a concern. When using tf.squeeze, always pass the squeeze dimension explicitly to avoid surprises.
For the most part, the mapping between Proto field types and TensorFlow dtypes is straightforward. However, there are a few special cases:
A proto field that contains a submessage or group can only be converted to DT_STRING (the serialized submessage). This is to reduce the complexity of the API. The resulting string can be used as input to another instance of the decode_proto op.
TensorFlow lacks support for unsigned integers. The ops represent uint64 types as a DT_INT64 with the same twos-complement bit pattern (the obvious way). Unsigned int32 values can be represented exactly by specifying type DT_INT64, or using twos-complement if the caller specifies DT_INT32 in the output_types attribute.
Both binary and text proto serializations are supported, and can be chosen using the format attribute.
The descriptor_source attribute selects the source of protocol descriptors to consult when looking up message_type. This may be:
An empty string or "local://", in which case protocol descriptors are created for C++ (not Python) proto definitions linked to the binary.
A file, in which case protocol descriptors are created from the file, which is expected to contain a FileDescriptorSet serialized as a string. NOTE: You can build a descriptor_source file using the --descriptor_set_out and --include_imports options to the protocol compiler protoc.
A "bytes://", in which protocol descriptors are created from <bytes>, which is expected to be a FileDescriptorSet serialized as a string.


Convert raw byte strings into tensors.
fixed_length must be a multiple of the size of out_type. fixed_length must be specified if the elements of input_bytes are of variable length.


Deserialize and concatenate SparseTensors from a serialized minibatch.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.deserialize_many_sparse, tf.compat.v1.io.deserialize_many_sparse
The input serialized_sparse must be a string matrix of shape [N x 3] where N is the minibatch size and the rows correspond to packed outputs of serialize_sparse. The ranks of the original SparseTensor objects must all match. When the final SparseTensor is created, it has rank one higher than the ranks of the incoming SparseTensor objects (they have been concatenated along a new row dimension).
The output SparseTensor object's shape values for all dimensions but the first are the max across the input SparseTensor objects' shape values for the corresponding dimensions. Its first shape value is N, the minibatch size.
The input SparseTensor objects' indices are assumed ordered in standard lexicographic order. If this is not the case, after this step run sparse.reorder to restore index ordering.
For example, if the serialized input is a [2, 3] matrix representing two original SparseTensor objects:
and
then the final deserialized SparseTensor will be:
All of the serialized SparseTensors must have had the same rank and type.


Encode strings into web-safe base64 format.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.encode_base64, tf.compat.v1.io.encode_base64
Refer to the following article for more information on base64 format: en.wikipedia.org/wiki/Base64. Base64 strings may have padding with '=' at the end so that the encoded has length multiple of 4. See Padding section of the link above.
Web-safe means that the encoder uses - and _ instead of + and /.


JPEG-encode an image.
Main aliases
tf.image.encode_jpeg
See Migration guide for more details.
tf.compat.v1.image.encode_jpeg, tf.compat.v1.io.encode_jpeg
image is a 3-D uint8 Tensor of shape [height, width, channels].
The attr format can be used to override the color format of the encoded output. Values can be:
If format is not specified or is the empty string, a default format is picked in function of the number of channels in image:


PNG-encode an image.
Main aliases
tf.image.encode_png
See Migration guide for more details.
tf.compat.v1.image.encode_png, tf.compat.v1.io.encode_png
image is a 3-D uint8 or uint16 Tensor of shape [height, width, channels] where channels is:
The ZLIB compression level, compression, can be -1 for the PNG-encoder default or a value from 0 to 9. 9 is the highest compression level, generating the smallest output, but is slower.


The op serializes protobuf messages provided in the input tensors.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.encode_proto
The types of the tensors in values must match the schema for the fields specified in field_names. All the tensors in values must have a common shape prefix, batch_shape.
The sizes tensor specifies repeat counts for each field. The repeat count (last dimension) of a each tensor in values must be greater than or equal to corresponding repeat count in sizes.
A message_type name must be provided to give context for the field names. The actual message descriptor can be looked up either in the linked-in descriptor pool or a filename provided by the caller using the descriptor_source attribute.
For the most part, the mapping between Proto field types and TensorFlow dtypes is straightforward. However, there are a few special cases:
A proto field that contains a submessage or group can only be converted to DT_STRING (the serialized submessage). This is to reduce the complexity of the API. The resulting string can be used as input to another instance of the decode_proto op.
TensorFlow lacks support for unsigned integers. The ops represent uint64 types as a DT_INT64 with the same twos-complement bit pattern (the obvious way). Unsigned int32 values can be represented exactly by specifying type DT_INT64, or using twos-complement if the caller specifies DT_INT32 in the output_types attribute.
The descriptor_source attribute selects the source of protocol descriptors to consult when looking up message_type. This may be:
An empty string or "local://", in which case protocol descriptors are created for C++ (not Python) proto definitions linked to the binary.
A file, in which case protocol descriptors are created from the file, which is expected to contain a FileDescriptorSet serialized as a string. NOTE: You can build a descriptor_source file using the --descriptor_set_out and --include_imports options to the protocol compiler protoc.
A "bytes://", in which protocol descriptors are created from <bytes>, which is expected to be a FileDescriptorSet serialized as a string.


Extract the shape information of a JPEG-encoded image.
Main aliases
tf.image.extract_jpeg_shape
See Migration guide for more details.
tf.compat.v1.image.extract_jpeg_shape, tf.compat.v1.io.extract_jpeg_shape
This op only parses the image header, so it is much faster than DecodeJpeg.


Configuration for parsing a fixed-length input feature.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.FixedLenFeature, tf.compat.v1.io.FixedLenFeature
To treat sparse input as dense, provide a default_value; otherwise, the parse functions will fail on any examples missing this feature.


Configuration for parsing a variable-length input feature into a Tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.FixedLenSequenceFeature, tf.compat.v1.io.FixedLenSequenceFeature
The resulting Tensor of parsing a single SequenceExample or Example has a static shape of [None] + shape and the specified dtype. The resulting Tensor of parsing a batch_size many Examples has a static shape of [batch_size, None] + shape and the specified dtype. The entries in the batch from different Examples will be padded with default_value to the maximum length present in the batch.
To treat a sparse input as dense, provide allow_missing=True; otherwise, the parse functions will fail on any examples missing this feature.


Public API for tf.io.gfile namespace.
class GFile: File I/O wrappers without thread locking.
copy(...): Copies data from src to dst.
exists(...): Determines whether a path exists or not.
glob(...): Returns a list of files that match the given pattern(s).
isdir(...): Returns whether the path is a directory or not.
listdir(...): Returns a list of entries contained within a directory.
makedirs(...): Creates a directory and all parent/intermediate directories.
mkdir(...): Creates a directory with the name given by path.
remove(...): Deletes the path located at 'path'.
rename(...): Rename or move a file / directory.
rmtree(...): Deletes everything under path recursively.
stat(...): Returns file statistics for a given path.
walk(...): Recursive directory tree generator for directories.


Copies data from src to dst.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.copy


Determines whether a path exists or not.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.exists


File I/O wrappers without thread locking.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.gfile.GFile, tf.compat.v1.gfile.Open, tf.compat.v1.io.gfile.GFile
The main roles of the tf.io.gfile module are:
The C++ FileSystem API supports multiple file system implementations, including local files, Google Cloud Storage (using a gs:// prefix, and HDFS (using an hdfs:// prefix). TensorFlow exports these as tf.io.gfile, so that you can use these implementations for saving and loading checkpoints, writing to TensorBoard logs, and accessing training data (among other uses). However, if all your files are local, you can use the regular Python file API without any problem.
View source
Closes FileIO. Should be called for the WritableFile to be flushed.
View source
Flushes the Writable file.
This only ensures that the data has made its way out of the process without any guarantees on whether it's written to disk. This means that the data would survive an application crash but not necessarily an OS crash.
View source
View source
Returns the contents of a file as a string.
Starts reading from current position in file.
View source
Reads the next line, keeping \n. At EOF, returns ''.
View source
Returns all lines from the file in a list.
View source
Seeks to the offset in the file. (deprecated arguments)
View source
Returns True as FileIO supports random access ops of seek()/tell()
View source
Returns the size of the file.
View source
Returns the current position in the file.
View source
Writes file_content to the file. Appends to the end of the file.
View source
Make usable with "with" statement.
View source
Make usable with "with" statement.
View source


Returns a list of files that match the given pattern(s).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.glob
The patterns are defined as strings. Supported patterns are defined here. Note that the pattern can be a Python iteratable of string patterns.
The format definition of the pattern is:
pattern: { term }
term:
character range:
See the C++ function GetMatchingPaths in core/platform/file_system.h for implementation details.


Returns whether the path is a directory or not.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.isdir


Returns a list of entries contained within a directory.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.listdir
The list is in arbitrary order. It does not contain the special entries "." and "..".


Creates a directory and all parent/intermediate directories.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.makedirs
It succeeds if path already exists and is writable.


Creates a directory with the name given by path.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.mkdir
Notes: The parent directories need to exist. Use tf.io.gfile.makedirs instead if there is the possibility that the parent dirs don't exist.


Deletes the path located at 'path'.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.remove


Rename or move a file / directory.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.rename


Deletes everything under path recursively.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.rmtree


Returns file statistics for a given path.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.stat


Recursive directory tree generator for directories.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.gfile.walk


Convenience function to check if the 'contents' encodes a JPEG image.
Main aliases
tf.image.is_jpeg
See Migration guide for more details.
tf.compat.v1.image.is_jpeg, tf.compat.v1.io.is_jpeg


Returns the set of files matching one or more glob patterns.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.matching_files, tf.compat.v1.matching_files
Note that this routine only supports wildcard characters in the basename portion of the pattern, not in the directory portion. Note also that the order of filenames returned is deterministic.


Save the list of files matching pattern, so it is only computed once.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.match_filenames_once, tf.compat.v1.train.match_filenames_once


Parses Example protos into a dict of tensors.
Parses a number of serialized Example protos given in serialized. We refer to serialized as a batch with batch_size many entries of individual Example protos.
example_names may contain descriptive names for the corresponding serialized protos. These may be useful for debugging purposes, but they have no effect on the output. If not None, example_names must be the same length as serialized.
This op parses serialized examples into a dictionary mapping keys to Tensor SparseTensor, and RaggedTensor objects. features is a dict from keys to VarLenFeature, SparseFeature, RaggedFeature, and FixedLenFeature objects. Each VarLenFeature and SparseFeature is mapped to a SparseTensor; each FixedLenFeature is mapped to a Tensor; and each RaggedFeature is mapped to a RaggedTensor.
Each VarLenFeature maps to a SparseTensor of the specified type representing a ragged matrix. Its indices are [batch, index] where batch identifies the example in serialized, and index is the value's index in the list of values associated with that feature and example.
Each SparseFeature maps to a SparseTensor of the specified type representing a Tensor of dense_shape [batch_size] + SparseFeature.size. Its values come from the feature in the examples with key value_key. A values[i] comes from a position k in the feature of an example at batch entry batch. This positional information is recorded in indices[i] as [batch, index_0, index_1, ...] where index_j is the k-th value of the feature in the example at with key SparseFeature.index_key[j]. In other words, we split the indices (except the first index indicating the batch entry) of a SparseTensor by dimension into different features of the Example. Due to its complexity a VarLenFeature should be preferred over a SparseFeature whenever possible.
Each FixedLenFeature df maps to a Tensor of the specified type (or tf.float32 if not specified) and shape (serialized.size(),) + df.shape.
FixedLenFeature entries with a default_value are optional. With no default value, we will fail if that Feature is missing from any example in serialized.
Each FixedLenSequenceFeature df maps to a Tensor of the specified type (or tf.float32 if not specified) and shape (serialized.size(), None) + df.shape. All examples in serialized will be padded with default_value along the second dimension.
Each RaggedFeature maps to a RaggedTensor of the specified type. It is formed by stacking the RaggedTensor for each example, where the RaggedTensor for each individual example is constructed using the tensors specified by RaggedTensor.values_key and RaggedTensor.partition. See the tf.io.RaggedFeature documentation for details and examples.
For example, if one expects a tf.float32 VarLenFeature ft and three serialized Examples are provided:
then the output will look like:
If instead a FixedLenSequenceFeature with default_value = -1.0 and shape=[] is used then the output will look like:
Given two Example input protos in serialized:
And arguments
Then the output is a dictionary:
For dense results in two serialized Examples:
And the expected output is:
An alternative to VarLenFeature to obtain a SparseTensor is SparseFeature. For example, given two Example input protos in serialized:
And arguments
Then the output is a dictionary:
See the tf.io.RaggedFeature documentation for examples showing how RaggedFeature can be used to obtain RaggedTensors.


Parses a batch of SequenceExample protos.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.parse_sequence_example
Parses a vector of serialized SequenceExample protos given in serialized.
This op parses serialized sequence examples into a tuple of dictionaries, each mapping keys to Tensor and SparseTensor objects. The first dictionary contains mappings for keys appearing in context_features, and the second dictionary contains mappings for keys appearing in sequence_features.
At least one of context_features and sequence_features must be provided and non-empty.
The context_features keys are associated with a SequenceExample as a whole, independent of time / frame. In contrast, the sequence_features keys provide a way to access variable-length data within the FeatureList section of the SequenceExample proto. While the shapes of context_features values are fixed with respect to frame, the frame dimension (the first dimension) of sequence_features values may vary between SequenceExample protos, and even between feature_list keys within the same SequenceExample.
context_features contains VarLenFeature, RaggedFeature, and FixedLenFeature objects. Each VarLenFeature is mapped to a SparseTensor; each RaggedFeature is mapped to a RaggedTensor; and each FixedLenFeature is mapped to a Tensor, of the specified type, shape, and default value.
sequence_features contains VarLenFeature, RaggedFeature, and FixedLenSequenceFeature objects. Each VarLenFeature is mapped to a SparseTensor; each RaggedFeature is mapped to a RaggedTensor; and eachFixedLenSequenceFeatureis mapped to aTensor, each of the specified type. The shape will be(B,T,) + df.dense_shapeforFixedLenSequenceFeaturedf, whereBis the batch size, andTis the length of the associatedFeatureListin theSequenceExample. For instance,FixedLenSequenceFeature([])yields a scalar 2-DTensorof static shape[None, None]and dynamic shape[B, T], whileFixedLenSequenceFeature([k])(forint k >= 1) yields a 3-D matrixTensorof static shape[None, None, k]and dynamic shape[B, T, k]`.
Like the input, the resulting output tensors have a batch dimension. This means that the original per-example shapes of VarLenFeatures and FixedLenSequenceFeatures can be lost. To handle that situation, this op also provides dicts of shape tensors as part of the output. There is one dict for the context features, and one for the feature_list features. Context features of type FixedLenFeatures will not be present, since their shapes are already known by the caller. In situations where the input 'FixedLenFeature`s are of different lengths across examples, the shorter examples will be padded with default datatype values: 0 for numeric types, and the empty string for string types.
Each SparseTensor corresponding to sequence_features represents a ragged vector. Its indices are [time, index], where time is the FeatureList entry and index is the value's index in the list of values associated with that time.
FixedLenFeature entries with a default_value and FixedLenSequenceFeature entries with allow_missing=True are optional; otherwise, we will fail if that Feature or FeatureList is missing from any example in serialized.
example_name may contain a descriptive name for the corresponding serialized proto. This may be useful for debugging purposes, but it has no effect on the output. If not None, example_name must be a scalar.


Parses a single Example proto.
Similar to parse_example, except:
For dense tensors, the returned Tensor is identical to the output of parse_example, except there is no batch dimension, the output shape is the same as the shape given in dense_shape.
For SparseTensors, the first (batch) column of the indices matrix is removed (the indices matrix is a column vector), the values vector is unchanged, and the first (batch_size) entry of the shape vector is removed (it is now a single element vector).
One might see performance advantages by batching Example protos with parse_example instead of using this function directly.


Parses a single SequenceExample proto.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.parse_single_sequence_example, tf.compat.v1.parse_single_sequence_example
Parses a single serialized SequenceExample proto given in serialized.
This op parses a serialized sequence example into a tuple of dictionaries, each mapping keys to Tensor and SparseTensor objects. The first dictionary contains mappings for keys appearing in context_features, and the second dictionary contains mappings for keys appearing in sequence_features.
At least one of context_features and sequence_features must be provided and non-empty.
The context_features keys are associated with a SequenceExample as a whole, independent of time / frame. In contrast, the sequence_features keys provide a way to access variable-length data within the FeatureList section of the SequenceExample proto. While the shapes of context_features values are fixed with respect to frame, the frame dimension (the first dimension) of sequence_features values may vary between SequenceExample protos, and even between feature_list keys within the same SequenceExample.
context_features contains VarLenFeature, RaggedFeature, and FixedLenFeature objects. Each VarLenFeature is mapped to a SparseTensor; each RaggedFeature is mapped to a RaggedTensor; and each FixedLenFeature is mapped to a Tensor, of the specified type, shape, and default value.
sequence_features contains VarLenFeature, RaggedFeature, and FixedLenSequenceFeature objects. Each VarLenFeature is mapped to a SparseTensor; each RaggedFeature is mapped to a RaggedTensor; and each FixedLenSequenceFeature is mapped to a Tensor, each of the specified type. The shape will be (T,) + df.dense_shape for FixedLenSequenceFeature df, where T is the length of the associated FeatureList in the SequenceExample. For instance, FixedLenSequenceFeature([]) yields a scalar 1-D Tensor of static shape [None] and dynamic shape [T], while FixedLenSequenceFeature([k]) (for int k >= 1) yields a 2-D matrix Tensor of static shape [None, k] and dynamic shape [T, k].
Each SparseTensor corresponding to sequence_features represents a ragged vector. Its indices are [time, index], where time is the FeatureList entry and index is the value's index in the list of values associated with that time.
FixedLenFeature entries with a default_value and FixedLenSequenceFeature entries with allow_missing=True are optional; otherwise, we will fail if that Feature or FeatureList is missing from any example in serialized.
example_name may contain a descriptive name for the corresponding serialized proto. This may be useful for debugging purposes, but it has no effect on the output. If not None, example_name must be a scalar.
Note that the batch version of this function, tf.parse_sequence_example, is written for better memory efficiency and will be faster on large SequenceExamples.


Transforms a serialized tensorflow.TensorProto proto into a Tensor.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.parse_tensor, tf.compat.v1.parse_tensor


Configuration for passing a RaggedTensor input feature.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.RaggedFeature
value_key specifies the feature key for a variable-length list of values; and partitions specifies zero or more feature keys for partitioning those values into higher dimensions. Each element of partitions must be one of the following:
Where key is a feature key whose values are used to partition the values. Partitions are listed from outermost to innermost.
If len(partitions) == 0 (the default), then:
If len(partitions) == 1, then:
A feature from a single tf.Example is parsed into a 2D tf.RaggedTensor, where the values taken from the value_key are separated into rows using the partition key.
A feature from a batch of tf.Examples is parsed into a 3D tf.RaggedTensor, where the outer dimension is the batch dimension, the two inner dimensions are formed by separating the value_key values from each example into rows using that example's partition key.
If len(partitions) > 1, then:
A feature from a single tf.Example is parsed into a tf.RaggedTensor whose rank is len(partitions)+1, and whose ragged_rank is len(partitions).
A feature from a batch of tf.Examples is parsed into a tf.RaggedTensor whose rank is len(partitions)+2 and whose ragged_rank is len(partitions)+1, where the outer dimension is the batch dimension.
There is one exception: if the final (i.e., innermost) element(s) of partitions are UniformRowLengths, then the values are simply reshaped (as a higher-dimensional tf.Tensor), rather than being wrapped in a tf.RaggedTensor.
class RowLengths
class RowLimits
class RowSplits
class RowStarts
class UniformRowLength
class ValueRowIds


RowLengths(key,)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.RaggedFeature.RowLengths


RowLimits(key,)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.RaggedFeature.RowLimits


RowSplits(key,)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.RaggedFeature.RowSplits


RowStarts(key,)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.RaggedFeature.RowStarts


UniformRowLength(length,)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.RaggedFeature.UniformRowLength


ValueRowIds(key,)
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.RaggedFeature.ValueRowIds


Reads and outputs the entire contents of the input filename.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.read_file, tf.compat.v1.read_file


Serialize N-minibatch SparseTensor into an [N, 3] Tensor.
The SparseTensor must have rank R greater than 1, and the first dimension is treated as the minibatch dimension. Elements of the SparseTensor must be sorted in increasing order of this first dimension. The serialized SparseTensor objects going into each row of the output Tensor will have rank R-1.
The minibatch size N is extracted from sparse_shape[0].


Serialize a SparseTensor into a 3-vector (1-D Tensor) object.


Transforms a Tensor into a serialized TensorProto proto.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.serialize_tensor, tf.compat.v1.serialize_tensor


Configuration for parsing a sparse input feature from an Example.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.SparseFeature, tf.compat.v1.io.SparseFeature
Note, preferably use VarLenFeature (possibly in combination with a SequenceExample) in order to parse out SparseTensors instead of SparseFeature due to its simplicity.
Closely mimicking the SparseTensor that will be obtained by parsing an Example with a SparseFeature config, a SparseFeature contains a
value_key: The name of key for a Feature in the Example whose parsed Tensor will be the resulting SparseTensor.values.
index_key: A list of names - one for each dimension in the resulting SparseTensor whose indices[i][dim] indicating the position of the i-th value in the dim dimension will be equal to the i-th value in the Feature with key named index_key[dim] in the Example.
size: A list of ints for the resulting SparseTensor.dense_shape.
For example, we can represent the following 2D SparseTensor
with an Example input proto
and SparseFeature config with 2 index_keys


Options used for manipulating TFRecord files.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.TFRecordOptions, tf.compat.v1.python_io.TFRecordOptions
View source
Convert various option types to a unified string.


A class to write records to a TFRecords file.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.TFRecordWriter, tf.compat.v1.python_io.TFRecordWriter
TFRecords tutorial
TFRecords is a binary format which is optimized for high throughput data retrieval, generally in conjunction with tf.data. TFRecordWriter is used to write serialized examples to a file for later consumption. The key steps are:
Ahead of time:
Write the serialized data to one or more files
During training or evaluation:
Read serialized examples into memory
Parse (deserialize) examples
A minimal example is given below:
This class implements __enter__ and __exit__, and can be used in with blocks like a normal file. (See the usage example above.)
View source
Close the file.
View source
Flush the file.
View source
Write a string record to the file.
enter(self: object) -> object
exit(self: tensorflow.python._pywrap_record_io.RecordWriter, *args) -> None


Configuration for parsing a variable-length input feature.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.VarLenFeature, tf.compat.v1.io.VarLenFeature


Writes contents to the file at input filename. Creates file and recursively
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.write_file, tf.compat.v1.write_file
creates directory if not existing.


Writes a graph proto to a file.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.io.write_graph, tf.compat.v1.train.write_graph
The graph is written as a text proto unless as_text is False.
or


Checks whether x is a TF-native type that can be passed to many TF ops.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.is_tensor
Use is_tensor to differentiate types that can ingested by TensorFlow ops without any conversion (e.g., tf.Tensor, tf.SparseTensor, and tf.RaggedTensor) from types that need to be converted into tensors before they are ingested (e.g., numpy ndarray and Python scalars).
For example, in the following code block:
we check to make sure that t is a tensor (and convert it if not) before accessing its shape and dtype.


Implementation of the Keras API meant to be a high-level API for TensorFlow.
Detailed documentation and user guides are available at tensorflow.org.
activations module: Built-in activation functions.
applications module: Keras Applications are canned architectures with pre-trained weights.
backend module: Keras backend API.
callbacks module: Callbacks: utilities called at certain points during model training.
constraints module: Constraints: functions that impose constraints on weight values.
datasets module: Public API for tf.keras.datasets namespace.
estimator module: Keras estimator API.
experimental module: Public API for tf.keras.experimental namespace.
initializers module: Keras initializer serialization / deserialization.
layers module: Keras layers API.
losses module: Built-in loss functions.
metrics module: Built-in metrics.
mixed_precision module: Keras mixed precision API.
models module: Code for model cloning, plus model-related API entries.
optimizers module: Built-in optimizer classes.
preprocessing module: Keras data preprocessing utils.
regularizers module: Built-in regularizers.
utils module: Public API for tf.keras.utils namespace.
wrappers module: Public API for tf.keras.wrappers namespace.
class Model: Model groups layers into an object with training and inference features.
class Sequential: Sequential groups a linear stack of layers into a tf.keras.Model.
Input(...): Input() is used to instantiate a Keras tensor.


Built-in activation functions.
deserialize(...): Returns activation function given a string identifier.
elu(...): Exponential Linear Unit.
exponential(...): Exponential activation function.
gelu(...): Applies the Gaussian error linear unit (GELU) activation function.
get(...): Returns function.
hard_sigmoid(...): Hard sigmoid activation function.
linear(...): Linear activation function (pass-through).
relu(...): Applies the rectified linear unit activation function.
selu(...): Scaled Exponential Linear Unit (SELU).
serialize(...): Returns the string identifier of an activation function.
sigmoid(...): Sigmoid activation function, sigmoid(x) = 1 / (1 + exp(-x)).
softmax(...): Softmax converts a real vector to a vector of categorical probabilities.
softplus(...): Softplus activation function, softplus(x) = log(exp(x) + 1).
softsign(...): Softsign activation function, softsign(x) = x / (abs(x) + 1).
swish(...): Swish activation function, swish(x) = x * sigmoid(x).
tanh(...): Hyperbolic tangent activation function.


Returns activation function given a string identifier.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.deserialize


Exponential Linear Unit.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.elu
The exponential linear unit (ELU) with alpha > 0 is: x if x > 0 and alpha * (exp(x) - 1) if x < 0 The ELU hyperparameter alpha controls the value to which an ELU saturates for negative net inputs. ELUs diminish the vanishing gradient effect.
ELUs have negative values which pushes the mean of the activations closer to zero. Mean activations that are closer to zero enable faster learning as they bring the gradient closer to the natural gradient. ELUs saturate to a negative value when the argument gets smaller. Saturation means a small derivative which decreases the variation and the information that is propagated to the next layer.
Fast and Accurate Deep Network Learning by Exponential Linear Units (ELUs) (Clevert et al, 2016)


Exponential activation function.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.exponential


Applies the Gaussian error linear unit (GELU) activation function.
Gaussian error linear unit (GELU) computes x * P(X <= x), where P(X) ~ N(0, 1). The (GELU) nonlinearity weights inputs by their value, rather than gates inputs by their sign as in ReLU.


Returns function.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.get


Hard sigmoid activation function.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.hard_sigmoid
A faster approximation of the sigmoid activation.


Linear activation function (pass-through).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.linear


Applies the rectified linear unit activation function.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.relu
With default values, this returns the standard ReLU activation: max(x, 0), the element-wise maximum of 0 and the input tensor.
Modifying default parameters allows you to use non-zero thresholds, change the max value of the activation, and to use a non-zero multiple of the input for values below the threshold.


Scaled Exponential Linear Unit (SELU).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.selu
The Scaled Exponential Linear Unit (SELU) activation function is defined as:
where alpha and scale are pre-defined constants (alpha=1.67326324 and scale=1.05070098).
Basically, the SELU activation function multiplies scale (> 1) with the output of the tf.keras.activations.elu function to ensure a slope larger than one for positive inputs.
The values of alpha and scale are chosen so that the mean and variance of the inputs are preserved between two consecutive layers as long as the weights are initialized correctly (see tf.keras.initializers.LecunNormal initializer) and the number of input units is "large enough" (see reference paper for more information).


Returns the string identifier of an activation function.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.serialize


Sigmoid activation function, sigmoid(x) = 1 / (1 + exp(-x)).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.sigmoid
Applies the sigmoid activation function. For small values (<-5), sigmoid returns a value close to zero, and for large values (>5) the result of the function gets close to 1.
Sigmoid is equivalent to a 2-element Softmax, where the second element is assumed to be zero. The sigmoid function always returns a value between 0 and 1.


Softmax converts a real vector to a vector of categorical probabilities.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.softmax
The elements of the output vector are in range (0, 1) and sum to 1.
Each vector is handled independently. The axis argument sets which axis of the input the function is applied along.
Softmax is often used as the activation for the last layer of a classification network because the result could be interpreted as a probability distribution.
The softmax of each vector x is computed as exp(x) / tf.reduce_sum(exp(x)).
The input values in are the log-odds of the resulting probability.


Softplus activation function, softplus(x) = log(exp(x) + 1).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.softplus


Softsign activation function, softsign(x) = x / (abs(x) + 1).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.softsign


Swish activation function, swish(x) = x * sigmoid(x).
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.swish
Swish activation function which returns x*sigmoid(x). It is a smooth, non-monotonic function that consistently matches or outperforms ReLU on deep networks, it is unbounded above and bounded below.


Hyperbolic tangent activation function.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.activations.tanh


Keras Applications are canned architectures with pre-trained weights.
densenet module: DenseNet models for Keras.
efficientnet module: EfficientNet models for Keras.
imagenet_utils module: Utilities for ImageNet data preprocessing & prediction decoding.
inception_resnet_v2 module: Inception-ResNet V2 model for Keras.
inception_v3 module: Inception V3 model for Keras.
mobilenet module: MobileNet v1 models for Keras.
mobilenet_v2 module: MobileNet v2 models for Keras.
mobilenet_v3 module: MobileNet v3 models for Keras.
nasnet module: NASNet-A models for Keras.
resnet module: ResNet models for Keras.
resnet50 module: Public API for tf.keras.applications.resnet50 namespace.
resnet_v2 module: ResNet v2 models for Keras.
vgg16 module: VGG16 model for Keras.
vgg19 module: VGG19 model for Keras.
xception module: Xception V1 model for Keras.
DenseNet121(...): Instantiates the Densenet121 architecture.
DenseNet169(...): Instantiates the Densenet169 architecture.
DenseNet201(...): Instantiates the Densenet201 architecture.
EfficientNetB0(...): Instantiates the EfficientNetB0 architecture.
EfficientNetB1(...): Instantiates the EfficientNetB1 architecture.
EfficientNetB2(...): Instantiates the EfficientNetB2 architecture.
EfficientNetB3(...): Instantiates the EfficientNetB3 architecture.
EfficientNetB4(...): Instantiates the EfficientNetB4 architecture.
EfficientNetB5(...): Instantiates the EfficientNetB5 architecture.
EfficientNetB6(...): Instantiates the EfficientNetB6 architecture.
EfficientNetB7(...): Instantiates the EfficientNetB7 architecture.
InceptionResNetV2(...): Instantiates the Inception-ResNet v2 architecture.
InceptionV3(...): Instantiates the Inception v3 architecture.
MobileNet(...): Instantiates the MobileNet architecture.
MobileNetV2(...): Instantiates the MobileNetV2 architecture.
MobileNetV3Large(...): Instantiates the MobileNetV3Large architecture.
MobileNetV3Small(...): Instantiates the MobileNetV3Small architecture.
NASNetLarge(...): Instantiates a NASNet model in ImageNet mode.
NASNetMobile(...): Instantiates a Mobile NASNet model in ImageNet mode.
ResNet101(...): Instantiates the ResNet101 architecture.
ResNet101V2(...): Instantiates the ResNet101V2 architecture.
ResNet152(...): Instantiates the ResNet152 architecture.
ResNet152V2(...): Instantiates the ResNet152V2 architecture.
ResNet50(...): Instantiates the ResNet50 architecture.
ResNet50V2(...): Instantiates the ResNet50V2 architecture.
VGG16(...): Instantiates the VGG16 model.
VGG19(...): Instantiates the VGG19 architecture.
Xception(...): Instantiates the Xception architecture.


DenseNet models for Keras.
DenseNet121(...): Instantiates the Densenet121 architecture.
DenseNet169(...): Instantiates the Densenet169 architecture.
DenseNet201(...): Instantiates the Densenet201 architecture.
decode_predictions(...): Decodes the prediction of an ImageNet model.
preprocess_input(...): Preprocesses a tensor or Numpy array encoding a batch of images.


Decodes the prediction of an ImageNet model.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.applications.densenet.decode_predictions


Preprocesses a tensor or Numpy array encoding a batch of images.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.applications.densenet.preprocess_input
Usage example with applications.MobileNet:
The input pixels values are scaled between 0 and 1 and each channel is normalized with respect to the ImageNet dataset.


Instantiates the Densenet121 architecture.
Main aliases
tf.keras.applications.densenet.DenseNet121
See Migration guide for more details.
tf.compat.v1.keras.applications.DenseNet121, tf.compat.v1.keras.applications.densenet.DenseNet121
Optionally loads weights pre-trained on ImageNet. Note that the data format convention used by the model is the one specified in your Keras config at ~/.keras/keras.json.


Instantiates the Densenet169 architecture.
Main aliases
tf.keras.applications.densenet.DenseNet169
See Migration guide for more details.
tf.compat.v1.keras.applications.DenseNet169, tf.compat.v1.keras.applications.densenet.DenseNet169
Optionally loads weights pre-trained on ImageNet. Note that the data format convention used by the model is the one specified in your Keras config at ~/.keras/keras.json.


Instantiates the Densenet201 architecture.
Main aliases
tf.keras.applications.densenet.DenseNet201
See Migration guide for more details.
tf.compat.v1.keras.applications.DenseNet201, tf.compat.v1.keras.applications.densenet.DenseNet201
Optionally loads weights pre-trained on ImageNet. Note that the data format convention used by the model is the one specified in your Keras config at ~/.keras/keras.json.


EfficientNet models for Keras.
EfficientNetB0(...): Instantiates the EfficientNetB0 architecture.
EfficientNetB1(...): Instantiates the EfficientNetB1 architecture.
EfficientNetB2(...): Instantiates the EfficientNetB2 architecture.
EfficientNetB3(...): Instantiates the EfficientNetB3 architecture.
EfficientNetB4(...): Instantiates the EfficientNetB4 architecture.
EfficientNetB5(...): Instantiates the EfficientNetB5 architecture.
EfficientNetB6(...): Instantiates the EfficientNetB6 architecture.
EfficientNetB7(...): Instantiates the EfficientNetB7 architecture.
decode_predictions(...): Decodes the prediction of an ImageNet model.
preprocess_input(...)


Decodes the prediction of an ImageNet model.
Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.applications.efficientnet.decode_predictions


Compat aliases for migration
See Migration guide for more details.
tf.compat.v1.keras.applications.efficientnet.preprocess_input


Instantiates the EfficientNetB0 architecture.
Main aliases
tf.keras.applications.efficientnet.EfficientNetB0
See Migration guide for more details.
tf.compat.v1.keras.applications.EfficientNetB0, tf.compat.v1.keras.applications.efficientnet.EfficientNetB0
Optionally loads weights pre-trained on ImageNet. Note that the data format convention used by the model is the one specified in your Keras config at ~/.keras/keras.json. If you have never configured it, it defaults to "channels_last".


Instantiates the EfficientNetB1 architecture.
Main aliases
tf.keras.applications.efficientnet.EfficientNetB1
See Migration guide for more details.
tf.compat.v1.keras.applications.EfficientNetB1, tf.compat.v1.keras.applications.efficientnet.EfficientNetB1
Optionally loads weights pre-trained on ImageNet. Note that the data format convention used by the model is the one specified in your Keras config at ~/.keras/keras.json. If you have never configured it, it defaults to "channels_last".


Instantiates the EfficientNetB2 architecture.
Main aliases
tf.keras.applications.efficientnet.EfficientNetB2
See Migration guide for more details.
tf.compat.v1.keras.applications.EfficientNetB2, tf.compat.v1.keras.applications.efficientnet.EfficientNetB2
Optionally loads weights pre-trained on ImageNet. Note that the data format convention used by the model is the one specified in your Keras config at ~/.keras/keras.json. If you have never configured it, it defaults to "channels_last".


Instantiates the EfficientNetB3 architecture.
Main aliases
tf.keras.applications.efficientnet.EfficientNetB3
See Migration guide for more details.
tf.compat.v1.keras.applications.EfficientNetB3, tf.compat.v1.keras.applications.efficientnet.EfficientNetB3
Optionally loads weights pre-trained on ImageNet. Note that the data format convention used by the model is the one specified in your Keras config at ~/.keras/keras.json. If you have never configured it, it defaults to "channels_last".