训练速度慢,GPU占用率低
Created by: imistyrain
paddlepaddle-gpu 1.2 ,训练用的卡为P40,单卡测 所用代码,已去除读取模块,由np生成的随机数直接灌入数据.
#coding=utf-8
import paddle.fluid as fluid
import numpy as np
import models
import time
import paddle.fluid.profiler as profiler
def test_speed():
image = fluid.layers.data(name="image", shape=[3, 224, 224])
#label = fluid.layers.data(name="label", shape=[1], dtype="int64")
model=models.__dict__["AlexNet"]()
predict=model.net(image)
#place = fluid.CPUPlace()
place=fluid.CUDAPlace(0)
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
profiler.start_profiler('GPU')
index=0
while True:
t1 = time.time()
results=exe.run(feed={"image":np.random.random(size=(32, 3, 224, 224)).astype('float32')},
fetch_list=[predict])
t2=time.time()
print("time:",t2-t1)
if index==2:
profiler.reset_profiler()
if index>=4:
profiler.stop_profiler('total', 'profile')
index+=1
if __name__=="__main__":
test_speed()
profile出来,GPU大段时间空闲,CPU中有80%的时间不知在干啥.