application_vnd.jupyter.stderr_output_2.png text_plain_output_1.png
import keras

import tensorflow as tf

tpu = tf.distribute.cluster_resolver.TPUClusterResolver()
tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
tpu_strategy = tf.distribute.experimental.TPUStrategy(tpu)

img_height, img_width = (256, 256)
checkpoint_filepath = './weights.best.hdf5'
with tpu_strategy.scope():
    train_datagen = keras.preprocessing.image.ImageDataGenerator(rescale=1.0 / 255, shear_range=0.2, zoom_range=0.2, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, validation_split=0.2)
    train_generator = train_datagen.flow_from_directory(train_data_dir, target_size=(img_height, img_width), batch_size=batch_size, class_mode='sparse', subset='training')
    validation_generator = train_datagen.flow_from_directory(train_data_dir, target_size=(img_height, img_width), batch_size=batch_size, class_mode='sparse', subset='validation')
    test_datagen = keras.preprocessing.image.ImageDataGenerator(rescale=1.0 / 255)
    es = keras.callbacks.EarlyStopping(monitor='val_loss', mode='min', verbose=1, patience=200)
    mc = keras.callbacks.ModelCheckpoint(checkpoint_filepath, monitor='val_accuracy', mode='max', verbose=1, save_best_only=True)
    input_tensor = keras.layers.Input(shape=(img_height, img_width, 3))
    v3 = keras.applications.InceptionV3(include_top=False, weights='imagenet', input_tensor=input_tensor, input_shape=None, pooling=None, classes=2, classifier_activation='softmax')
    model = keras.models.Sequential()
    model.add(v3)
    model.add(keras.layers.GlobalAveragePooling2D())
    model.add(keras.layers.Dropout(0.2))
    model.add(keras.layers.Dense(4096, activation='relu'))
    model.add(keras.layers.Dropout(0.2))
    model.add(keras.layers.Dense(64, activation='relu'))
    model.add(keras.layers.Dropout(0.2))
    model.add(keras.layers.Dense(10, activation='softmax'))
    train_data_dir = '/kaggle/input/burning/train/'
    test_data_dir = '/kaggle/input/burning/test/'
    batch_size = 64
    epochs = 128
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

model.fit_generator(train_generator, epochs=epochs, validation_data=validation_generator, callbacks=[mc, es])