Tensorflow directml How to use any GPU for Deep Learning!

preview_player
Показать описание
Hi guys! In this video I'll be showing how to use almost any GPU for Deep Learning, what you need first is a GPU that is able to run Directx 12, then the second step is to install tensorflow-directml, tensorflow-directml is a runtime for TensorFlow that uses the DirectX API for computing making it possible to use a wide range of GPUs for training Deep Learning models, the performance increase versus training on CPU is noticeable also you can train on the background while using your PC.
Рекомендации по теме
Комментарии
Автор

Do you think there is a difference in times when using ROCm? I also have an APU. Thanks in advance

vif
Автор

The benchmark code:

import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPool2D, Flatten, Dense
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
from time import time


def conv_model(device, filters, kz):

with tf.device(device):

model = Sequential()
model.add(Conv2D(filters, kernel_size=3, padding='same', activation='relu', input_shape=(28, 28, 1)))

model.add(Conv2D(filters, kernel_size=3, padding='same', activation='relu'))

model.add(Conv2D(filters, kernel_size=3, padding='same', activation='relu'))

model.add(Flatten())
model.add(Dense(10, activation='softmax'))

model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['acc'])
model.summary()

return model


def run(model, x_train, y_train, epochs=128, batch_size=32):

start = time()
model.fit(x_train, y_train, epochs=epochs, batch_size=batch_size)
end = time()

return end - start


(x_train, y_train), (_, _) = mnist.load_data()

x_train = x_train / 255.0 # Normalize x train
x_train = x_train.reshape(-1, 28, 28, 1) # Add the cnannel axis
y_train = to_categorical(y_train, num_classes=10) # convert to one-hot

cpu_model = conv_model('CPU', 64, 3) # 64 filters, kernel size of 3
#from tensorflow.python.client import device_lib
# GET GPU DEVICE NAME IF 'GPU' DO NOT WORK
gpu_model = conv_model('GPU', 64, 3) # 64 filters, kernel size of 3, change for

epochs = 1
bz = 16

conv_cpu_time = run(cpu_model, x_train, y_train, epochs=epochs, batch_size=bz)
conv_gpu_time = run(gpu_model, x_train, y_train, epochs=epochs, batch_size=bz)

print('Time to train on CPU for 8 epochs: {}
print('Time to train on GPU for 8 epochs: {}

leosmi
Автор

Compatible with training models with Object Detection Api?

granatapfel
Автор

Can I Use Intel IrisXe In This Case???

flarexlucifer
Автор

Fiz o benchmark e deu a mesma coisa pra cpu e gpu. Uso intel core i5-11gen e intel iriz Xe.

Time to train on CPU for 8 epochs: 45.157583236694336 seconds
Time to train on GPU for 8 epochs: 42.85075354576111 seconds

Estou decepcionado...

leosmi