Created
February 14, 2021 04:10
-
-
Save patharanordev/d016eb2cb31be342a1b9c2b1644f5899 to your computer and use it in GitHub Desktop.
Test PlaidML performance via simple VGG model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import numpy as np | |
import os | |
import time | |
os.environ['KERAS_BACKEND'] = 'plaidml.keras.backend' | |
import keras | |
import keras.applications as kapp | |
from keras.datasets import cifar10 | |
(x_train, y_train_cats), (x_test, y_test_cats) = cifar10.load_data() | |
batch_size = 8 | |
x_train = x_train[:batch_size] | |
x_train = np.repeat(np.repeat(x_train, 7, axis=1), 7, axis=2) | |
model = kapp.VGG19() | |
model.compile(optimizer='sgd', loss='categorical_crossentropy', metrics=['accuracy']) | |
print('Running initial batch (compiling tile program)') | |
y = model.predict(x=x_train, batch_size=batch_size) | |
print('Timing inference...') | |
start = time.time() | |
for i in range(10): | |
y = model.predict(x=x_train, batch_size=batch_size) | |
print('Ran in {} seconds'.format(time.time() - start)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment