Skip to content

Commit fd505f4

Browse files
fyangftensorflower-gardener
authored andcommitted
Add functionality to create fake data and use that in train_test to show how an e2e training works.
PiperOrigin-RevId: 381368435
1 parent c73c012 commit fd505f4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

official/vision/beta/dataloaders/tfexample_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,24 @@ def create_classification_example(
143143
int64_list=tf.train.Int64List(value=labels))),
144144
})).SerializeToString()
145145
return serialized_example
146+
147+
148+
def create_3d_image_test_example(image_height: int, image_width: int,
149+
image_volume: int,
150+
image_channel: int) -> tf.train.Example:
151+
"""Creates 3D image and label."""
152+
images = np.random.rand(image_height, image_width, image_volume,
153+
image_channel)
154+
images = images.astype(np.float32)
155+
156+
labels = np.random.randint(
157+
low=2, size=(image_height, image_width, image_volume, image_channel))
158+
labels = labels.astype(np.float32)
159+
160+
feature = {
161+
IMAGE_KEY: (tf.train.Feature(
162+
bytes_list=tf.train.BytesList(value=[images.tobytes()]))),
163+
CLASSIFICATION_LABEL_KEY: (tf.train.Feature(
164+
bytes_list=tf.train.BytesList(value=[labels.tobytes()])))
165+
}
166+
return tf.train.Example(features=tf.train.Features(feature=feature))

0 commit comments

Comments
 (0)