Returns path to PNG picture.
(height=None, width=None, channels=CHANNELS_NB)
| 50 | |
| 51 | |
| 52 | def 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 | |
| 70 | def get_random_audio(duration=_AUDIO_DURATION, sample=_SAMPLE_RATE): |
no test coverage detected