TensorSpec: Interface between variable batches and fixed features
Enter the shape, data type and optional name of the signature describing the length.
Learning objectives and first steps2 objectives 2 first fixes
Try to do it after reading
- Write the input signature as a clear shape agreement
- Explaining unknown dimensions does not equal any input
Suggested first
- Python Basic Syntax:
- Counting and training closed
Deployment requires a commitment to reject misentry
Enter the shape, data type and optional name of the signature describing the length. It affects both the reuse of maps and how the caller checks the data. For batch predictions of fixed eight characteristics, the shape is [None,8], which means that the batch length is fixed and each record has eight features at all times. None is an unknown dimension, not all constraints disappear.
Assuming a weight of [8,2], input [3,8] gets [3,] input [11,8] gets [11,2]. The two batches could match the same signature. Inputs [3,7] are missing a characteristic; Automatic zeroing may mask the omission in the upstream field and should be allowed by a clear pre-treatment agreement rather than by the model.
Data types are also part of the interface. A business field reads integer numbers in a file, which does not mean that the service function should receive any integer and float arrays simultaneously. Clear where the conversion takes place to prevent deviations from offline training using float32, and the service end using another precision or character encoding.
Unknown shape and running-time shape
Static shapes represent the information known at the time of the construction, and the shape is determined by the actual length of the stretch. If the batch is unknown, the Python side cannot directly use the unknown to create a fixed length list. A volume calculation that accepts dynamic shapes should be used. Conversely, the fixed weight dimension of the network usually needs to be clear when constructed and not all axes can be dynamicized.
Sequence input may be [None], None, 16]: lot and length changes with 16-dimensional characteristics per step. The length or mask agreement is also required at this time, as the signature specifies only the size and does not tell the model if the position to be filled is valid. Inputs of identical shapes may vary in the true sequence length and may not be judged by the labels as approximate denominators solely on the basis of shape.
When writing tests for interfaces, include at least a legitimate short batch, a legitimate long batch, the number of error features, the type of error and whether the empty batch is supported. The input check proves only that the form meets the requirements and does not prove that the order, unit or sample point is correct.
This section uses the semantics of TensorFlow 2 TensorSpec and tf. function; If you export a Keras model, you also need to check the actual export terminal. Shape transport is sort of a manual deduction. The signature should be edited in conjunction with the feature dictionary to avoid simply updating the model file while retaining the old call format.
[None, 8] Can you receive [5,8,1]?
No, you can't. The extra axis changes the length of the length and the unknown batch subaxis does not allow any dimension to be added.
Signing accepted [2,4,16], which indicates that each sequence is four?
Can't. 4 Could be public length after completion. The true length still requires a visible length vector or mask expression.
Sources and reconciliations
Definitions, methods and interfaces are available.
Figures and calculations are reorganized according to this chapter. Mathematical measurements, framework operations and real business effects are described separately in the body of the text.