Open ninopira opened 3 years ago
https://www.kaggle.com/itokashi/easy-eda
healthy 516
multiple_diseases 91
rust 622
scab 592
オレンジの斑点
茶色の斑点
元notebook: https://www.kaggle.com/xhlulu/plant-pathology-very-concise-tpu-efficientnet?scriptVersionId=32659758 自分のnotebook: https://www.kaggle.com/itokashi/very-concise-tpu-efficientnet-copy
写経+debug
tf.distribute.cluster_resolver.TPUClusterResolver()
tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
strategy = tf.distribute.experimental.TPUStrategy(tpu)
コメント
def decode_image(filename, label=None, image_size=(512, 512)):
bits = tf.io.read_file(filename)
image = tf.image.decode_jpeg(bits, channels=3)
image = tf.cast(image, tf.float32) / 255.0
image = tf.image.resize(image, image_size)
if label is None:
return image
else:
return image, label
def data_augment(image, label=None):
image = tf.image.random_flip_left_right(image)
image = tf.image.random_flip_up_down(image)
if label is None:
return image
else:
return image, label
コメント
train_dataset = (
tf.data.Dataset
.from_tensor_slices((train_paths, train_labels))
.map(decode_image, num_parallel_calls=AUTO)
.cache()
.map(data_augment, num_parallel_calls=AUTO)
.repeat()
.shuffle(512)
.batch(BATCH_SIZE)
.prefetch(AUTO)
)
valid_dataset = (
tf.data.Dataset
.from_tensor_slices((valid_paths, valid_labels))
.map(decode_image, num_parallel_calls=AUTO)
.batch(BATCH_SIZE)
.cache()
.prefetch(AUTO)
)
test_dataset = (
tf.data.Dataset
.from_tensor_slices(test_paths)
.map(decode_image, num_parallel_calls=AUTO)
.batch(BATCH_SIZE)
)
strategy = tf.distribute.experimental.TPUStrategy(tpu)
は「」TPUで分散学習しますよー」と宣言しているイメージ
with strategy.scope():
model = tf.keras.Sequential([
efn.EfficientNetB7(
input_shape=(512, 512, 3),
weights='imagenet',
include_top=False
),
L.GlobalAveragePooling2D(),
L.Dense(train_labels.shape[1], activation='softmax')
])
model.compile(
optimizer='adam',
loss = 'categorical_crossentropy',
metrics=['categorical_accuracy']
)
model.summary()
とりあえずTPUは掴んだっぽい ただいまいちフル活用できていないっぽそう
https://www.kaggle.com/ateplyuk/fork-of-plant-2020-tpu-915e9c
対象コンペ