-
Notifications
You must be signed in to change notification settings - Fork 0
/
keras34_gpu_test.py
57 lines (42 loc) · 1.6 KB
/
keras34_gpu_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#gpu와 cpu 성능 테스트 모델
import tensorflow as tf
from keras.applications import Xception
from keras.utils import multi_gpu_model
import numpy as np
import datetime
''' 처리시간
GPU 처리시간 : 0:00:32.044086
CPU 처리시간 : 0:00:54.327245 '''
num_samples =100
height = 71
width = 71
num_classes = 100
print("GPU 시간 측정 시작 !!!")
start1 = datetime.datetime.now()
with tf.device('/gpu:0'):
model = Xception(weights=None,
input_shape=(height, width, 3), classes=num_classes)
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
# Generate dummy data.
x = np.random.random((num_samples, height, width, 3))
y = np.random.random((num_samples, num_classes))
model.fit(x, y, epochs=3, batch_size=16)
model.save('./model/time_check1.h5')
end1 = datetime.datetime.now()
time_delta1 = end1 - start1
print("GPU 시간 측정 끝 !!!")
print("CPU 시간 측정 시작 !!!")
start2 = datetime.datetime.now()
with tf.device('/cpu:0'):
model = Xception(weights=None,
input_shape=(height, width, 3), classes=num_classes)
model.compile(loss='categorical_crossentropy', optimizer='rmsprop')
# Generate dummy data.
x = np.random.random((num_samples, height, width, 3))
y = np.random.random((num_samples, num_classes))
model.fit(x, y, epochs=3, batch_size=16)
model.save('./model/time_check2.h5')
end2 = datetime.datetime.now()
time_delta2 = end2 - start2
print('GPU 처리시간 : ', time_delta1)
print('CPU 처리시간 : ', time_delta2)