text_plain_output_1.png
import tensorflow as tf

import tensorflow.keras.layers as L

import tensorflow.keras.models as M

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)

with tpu_strategy.scope():
    def make_ann(n_in):
        inp = L.Input(shape=(n_in,), name='inp')
        d1 = L.Dense(100, activation='relu', name='d1')(inp)
        d2 = L.Dense(100, activation='relu', name='d2')(d1)
        preds = L.Dense(1, activation='sigmoid', name='preds')(d2)
        model = M.Model(inp, preds, name='ANN')
        model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
        return model