Code Monkey home page Code Monkey logo

tpucolab's Introduction

TPUColab

Unlike GPU, to make code work in TPU, code needs to be changed.

TPUColab is a library to make TPU working in Colab Google with less code modification.

In most cases, only 2 lines code change is enough (not count the line of importing tpucolab).

Install

pip install tpucolab

In Colab Google Jupyter, for auto install and ensure using latest version of TPUColab, please add "!pip install -U tpucolab" at the first line of Jupyter cell

Requirements

Tensorflow

Import

from tpucolab import *

Initialization

tpucolab = TPUColab()

After initialization, text "Found TPU" will be shown in Colab Google Jupyter output

PS: If Initialization failed, please retry later. Google Colab, unfortunately, has TPU memory allocation issue occasionally.

Turn ordinal compiled Keras model to TPU model

tpucolab.compiled_model_to_tpu_model(model)

Now model is compatible with TPU

Train TPU model

Just as the same as ordinal Keras model, e.g.:

model.fit(X_train,Y_train,validation_data=(X_test,Y_test),epochs=9999)

Other Keras model functions can also be invoked in TPU model as usual.

Important Note

The following keras object (include but not all) should not be imported from keras.* . Should be imported from tensorflow.keras.*

Sequential, Model, Dense, Dropout, Flatten, Conv2D, MaxPooling2D

e.g. (wrong)

from keras.models import Sequential, Model
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D

e.g. (correct)

from tensorflow.keras.models import Sequential, Model
from tensorflow.keras.layers import Dense, Dropout, Flatten
from tensorflow.keras.layers import Conv2D, MaxPooling2D

Thanks

Google

tpucolab's People

Contributors

taomanwai avatar

Watchers

Vince Lynch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.