[PYTHON] Run Keras on Google Colaboratory TPU

Preparation

%tensorflow_version 2.x
import tensorflow as tf
print("Tensorflow version " + tf.__version__)

try:
  tpu = tf.distribute.cluster_resolver.TPUClusterResolver()  # TPU detection
  print('Running on TPU ', tpu.cluster_spec().as_dict()['worker'])
except ValueError:
  raise BaseException('ERROR: Not connected to a TPU runtime; please see the previous cell in this notebook for instructions!')

tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
tpu_strategy = tf.distribute.TPUStrategy(tpu)
def create_model():
  #model definition
  return model
with tpu_strategy.scope():
  model = create_model()

Learning part

Learn normally

history = model.fit( x_train, y_train, epochs = 50, batch_size = 2048, validation_data=(x_test, y_test))

Recommended Posts

Run Keras on Google Colaboratory TPU
Use TPU and Keras with Google Colaboratory
Use music21 on Google Colaboratory
Pandas 100 knocks on Google Colaboratory
Google colaboratory
[Python] Run Flask on Google App Engine
Google Colaboratory setup summary
Is it Google Colaboratory?
Run Django on PythonAnywhere
Run mysqlclient on Lambda
Run OpenMVG on Mac
"Deep Learning from scratch" Self-study memo (No. 14) Run the program in Chapter 4 on Google Colaboratory
Run Jupyter on Ubuntu on Windows
Run Openpose on Python (Windows)
Google Edge TPU Inference Overview
ls -R on Google Drive
Study Python with Google Colaboratory
Plotly Dash on Google Colab
Run Tensorflow 2.x on Python 3.7
Run Python CGI on CORESERVER
Run unix command on python
Run IPython Notebook on Docker
Run YOLO v3 on AWS v2
Try OpenCV with Google Colaboratory
Run CircuitPython on Seeeduino XIAO
Run Jupyter Notebook on windows
Tool organization: Google Colaboratory (updated 2020.2.24)
Run FreeBSD on Linux + qemu
[Keras] 75% accuracy on CIFAR10 dataset
Run OpenVino on macOS Catalina
Run YOLO v3 on AWS
How to use Google Colaboratory
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory