-
Notifications
You must be signed in to change notification settings - Fork 26
/
save_random_image_from_dataset_.py
71 lines (50 loc) · 1.81 KB
/
save_random_image_from_dataset_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# coding: utf-8
# In[28]:
import tensorflow as tf
import os
import numpy as np
from PIL import Image
from datetime import datetime
import random
class StoreImage(object):
def save(self):
(train_images, train_labels), (test_images, test_labels) = tf.keras.datasets.fashion_mnist.load_data()
folder_name = "./" + str(datetime.today().strftime("%Y%m%d%H%M"))
# make min folder
try:
if not(os.path.isdir(folder_name)):
os.makedirs(os.path.join(folder_name))
except OSError as e:
if e.errno != errno.EEXIST:
print("Failed to create directory!!!!!")
raise
# generate 10 ranom image (0~9999)
for i in range(10):
random_num = random.randint(0, 9999)
file_name = str(test_labels[random_num]) + "_" + str(i) + ".jpg"
im = Image.fromarray(test_images[random_num])
im.save(folder_name + "/" + file_name)
if __name__ == '__main__':
if os.getenv('FAIRING_RUNTIME', None) is None:
from kubeflow import fairing
from kubeflow.fairing.kubernetes import utils as k8s_utils
DOCKER_REGISTRY = 'kubeflow-registry.default.svc.cluster.local:30000'
fairing.config.set_builder(
'append',
image_name='store-fashion-minst',
base_image='brightfly/kubeflow-jupyter-lab:tf2.0-cpu',
registry=DOCKER_REGISTRY,
push=True)
# cpu 2, memory 5GiB
fairing.config.set_deployer('job',
namespace='dudaji',
pod_spec_mutators=[
k8s_utils.get_resource_mutator(cpu=0.5,
memory=0.5)])
fairing.config.run()
else:
remote = StoreImage()
remote.save()
# In[23]:
# In[ ]: