unittest_util
OneLayerTorchModel
¶
Bases: Module
Torch Model with one dense layer without activation function. * Model input shape: (3,) * Model output: (1,) * dense layer weight: [1.0, 2.0, 3.0]
How to feed_forward this model
model = OneLayerTorchModel()
x = torch.tensor([[1.0, 1.0, 1.0], [1.0, -1.0, -0.5]])
b = fe.backend.feed_forward(model, x) # [[6.0], [-2.5]]
Source code in fastestimator/fastestimator/test/unittest_util.py
TraceRun
¶
Class to simulate the trace calling protocol.
This serve for testing purpose without using estimator class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
trace |
Trace
|
Target trace to run. |
required |
batch |
Dict[str, Any]
|
Batch data from pipepline. |
required |
prediction |
Dict[str, Any]
|
Batch data from network. |
required |
Source code in fastestimator/fastestimator/test/unittest_util.py
check_img_similar
¶
Check whether img1 and img2 array are similar based on pixel to pixel comparision Args: img1: Image 1 img2: Image 2 ptol: Pixel value tolerance ntol: Number of pixel difference tolerace rate
Returns:
Type | Description |
---|---|
bool
|
Boolean of whether the images are similar |
Source code in fastestimator/fastestimator/test/unittest_util.py
fig_to_rgb_array
¶
Convert image in plt.Figure to numpy array
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fig |
Figure
|
Input figure object |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Image array |
Source code in fastestimator/fastestimator/test/unittest_util.py
img_to_rgb_array
¶
Read png file to numpy array (RGB)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
Image path |
required |
Returns:
Type | Description |
---|---|
ndarray
|
Image numpy array |
is_equal
¶
Check whether input objects are equal. The object type can be nested iterable (list, tuple, set, dict) and with elements such as int, float, np.ndarray, tf.Tensor, tf.Varaible, torch.Tensor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj1 |
Any
|
Input object 1 |
required |
obj2 |
Any
|
Input object 2 |
required |
assert_type |
bool
|
Whether to assert the same data type |
True
|
assert_dtype |
bool
|
Whether to assert the same dtype in case of nd.array, tf.Tensor, torch.Tensor |
False
|
Returns:
Type | Description |
---|---|
bool
|
Boolean of whether those two object are equal |
Source code in fastestimator/fastestimator/test/unittest_util.py
one_layer_tf_model
¶
Tensorflow Model with one dense layer without activation function. * Model input shape: (3,) * Model output: (1,) * dense layer weight: [1.0, 2.0, 3.0]
How to feed_forward this model
model = one_layer_tf_model()
x = tf.constant([[1.0, 1.0, 1.0], [1.0, -1.0, -0.5]])
b = fe.backend.feed_forward(model, x) # [[6.0], [-2.5]]
Returns:
Type | Description |
---|---|
Model
|
tf.keras.Model: The model |