Upload extract_images.py
Browse files- extract_images.py +19 -0
extract_images.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import base64
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import io
|
| 5 |
+
from tqdm import tqdm
|
| 6 |
+
|
| 7 |
+
filenames = tf.io.gfile.glob('./android_control*')
|
| 8 |
+
raw_dataset = tf.data.TFRecordDataset(filenames, compression_type='GZIP')
|
| 9 |
+
dataset_iterator = tf.compat.v1.data.make_one_shot_iterator(raw_dataset)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
for data in tqdm(dataset_iterator):
|
| 13 |
+
example = tf.train.Example.FromString(data.numpy())
|
| 14 |
+
episode_id = example.features.feature['episode_id'].int64_list.value
|
| 15 |
+
# Save images to png files
|
| 16 |
+
for i, image_data in enumerate(screenshots):
|
| 17 |
+
image = Image.open(io.BytesIO(image_data))
|
| 18 |
+
image.save(f"./images/android_control_episode_{str(episode_id)}_{str(i)}.png")
|
| 19 |
+
|