Keras / Tensorflow で使う学習データセットからテクスチャアトラスを作成するコードを書きました。デバッグ、学習データセット作成の練習も兼ねています。
学習データセット CIFAR10 Small Images
https://keras.io/datasets/
https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
学習データセット CIFAR10 Small Images
https://keras.io/datasets/
https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
図 今回、生成したテクスチャアトラス(拡大)
図 生成したテクスチャアトラスの全体 8,000 x 6,400 texels (250 x 200 images)
コード
# source: https://github.com/keras-team/keras/blob/master/examples/cifar10_cnn.py # morishige, 2018 from keras.datasets import cifar10 # The data, shuffled and split between train and test sets: (x_train, y_train), (x_test, y_test) = cifar10.load_data() print('x_train shape:', x_train.shape) print(x_train.shape[0], 'train samples') print(x_test.shape[0], 'test samples') # for debug import numpy as np from PIL import Image def img_show(img, atlasX, atlasY): pil_img = Image.fromarray(np.uint8(img)) pil_img.show() img_name = 'cifar10_atlas_' + str(atlasY) + 'x' + str(atlasX) + '.jpg' pil_img.save(img_name) # get information img_count = x_train.shape[0] img_width = x_train.shape[1] img_height = x_train.shape[2] img_channels = x_train.shape[3] print('image count:', img_count) print('image size(%d, %d), channels(%d)' % (img_width, img_height, img_channels)) # generate image atlas atlas_xcount = 250 atlas_ycount = int(img_count / atlas_xcount) img_atlas = np.empty((img_height * atlas_ycount, img_width * atlas_xcount, img_channels), dtype='uint8') o_y = 0 o_x = 0 for y in range(atlas_ycount): o_y = y * img_height for x in range(atlas_xcount): o_x = x * img_width # image shape is (sample index, 32, 32, 3) img = x_train[y * atlas_xcount + x] img_atlas[o_y:o_y + img_height, o_x:o_x + img_width, :] = img # The image atlas shows and save to file img_show(img_atlas, atlas_xcount, atlas_ycount)
コメント
コメントを投稿