MCPcopy Create free account
hub / github.com/tensorflow/datasets / get_random_png

Function get_random_png

tensorflow_datasets/testing/fake_data_utils.py:52–67  ·  view source on GitHub ↗

Returns path to PNG picture.

(height=None, width=None, channels=CHANNELS_NB)

Source from the content-addressed store, hash-verified

50
51
52def get_random_png(height=None, width=None, channels=CHANNELS_NB):
53 """Returns path to PNG picture."""
54 # Big randomly generated pngs take large amounts of diskspace.
55 # Instead, we resize a 4x4 random image to the png size.
56 image = get_random_picture(4, 4, channels)
57 if (height is not None) and (width is not None):
58 image = tf.image.resize_nearest_neighbor(
59 tf.expand_dims(image, 0), (height, width)
60 )[0]
61 png = tf.image.encode_png(image)
62 with utils.nogpu_session() as sess:
63 res = sess.run(png)
64 fobj = tempfile.NamedTemporaryFile(delete=False, mode='wb', suffix='.PNG')
65 fobj.write(res)
66 fobj.close()
67 return fobj.name
68
69
70def get_random_audio(duration=_AUDIO_DURATION, sample=_SAMPLE_RATE):

Callers 1

create_zipfileFunction · 0.90

Calls 4

get_random_pictureFunction · 0.85
runMethod · 0.80
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected