前回まででデータを色々見てみたけど、やっとこ画像を触り始める。
これで画像をリサイズしたり、並べたりラベルつけたり
正直なにやってるかわからんから次回は再びもっと簡単なのに戻ろうね。
IMAGE_SIZE = 96
def _parse_fn(filename, label):
image_string = tf.io.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_string)
image_normalized = (tf.cast(image_decoded, tf.float32)/127.5) - 1
image_resized = tf.image.resize(image_normalized, (IMAGE_SIZE, IMAGE_SIZE))
return image_resized, label
次に学習する際に全体のデータからどれだけを使うかみたいなのの指定
だと解釈してるが合ってるのかは不明
from_tensor_slices メソッドでデータセットを構築した模様
シャッフルのサイズがめっちゃでかいのでランダムになる度合いを
高く設定しているっぽいがメモリとトレード・オフの関係にありそう。
BATCH_SIZE = 32
train_data = tf.data.Dataset.from_tensor_slices*1, types: (tf.float32, tf.int32)>
<BatchDataset shapes: *2, types: (tf.float32, tf.int32)>
<BatchDataset shapes: *2, types: (tf.float32, tf.int32)>
*1:tf.constant(train_filenames), tf.constant(train_labels))).map(_parse_fn).shuffle(buffer_size=10000).batch(BATCH_SIZE)
val_data = tf.data.Dataset.from_tensor_slices((tf.constant(val_filenames), tf.constant(val_labels))).map(_parse_fn).batch(BATCH_SIZE)
ちなみに
print(train_data)
print(val_data)
print(val_data)
したときの出力結果
<BatchDataset shapes: ((None, 96, 96, None), (None,
*2:None, 96, 96, None), (None,