在 julia 中对机器学习flux代码进行基准测试

问题描述

我正在尝试对下面提到的 Flux 代码性能进行基准测试:

#model
using Flux
vgg19() = Chain(            
    Conv((3,3),3 => 64,relu,pad=(1,1),stride=(1,1)),Conv((3,64 => 64,MaxPool((2,2)),64 => 128,128 => 128,128 => 256,256 => 256,256 => 512,512 => 512,Batchnorm(512),flatten,Dense(512,4096,relu),Dropout(0.5),Dense(4096,10),softmax
)

#data

using MLDatasets: CIFAR10
using Flux: onehotbatch
# Data comes pre-normalized in Julia
trainX,trainY = CIFAR10.traindata(Float32)
testX,testY = CIFAR10.testdata(Float32)
# One hot encode labels
trainY = onehotbatch(trainY,0:9)
testY = onehotbatch(testY,0:9)

#training

using Flux: crossentropy,@epochs
using Flux.Data: DataLoader
model = vgg19()
opt = Momentum(.001,.9)
loss(x,y) = crossentropy(model(x),y)
data = DataLoader(trainX,trainY,batchsize=64)
@epochs 100 Flux.train!(loss,params(model),data,opt)

我尝试使用内置的 tick()tock() 函数来测量时间。但是,这给出了执行密集比较的基本时间并且效率不高。 社区中的许多开发人员都推荐使用 BenchmarkTools.jl 包来对代码进行基准测试。但是当我尝试对 REPL 中的 ScikitLearn Model 进行基准测试时,它产生了警告;

WARNING: redeFinition of constant LogisticRegression. This may fail,cause incorrect answers,or produce other errors.

同样,我尝试使用 REPL@btime 中的上述代码进行基准测试,但它抛出此错误

julia> using BenchmarkTools
julia> @btime include("C:/Users/user/code.jl")
[ Info: Epoch 1
WARNING: both Flux and BenchmarkTools export "params"; uses of it in module Main must be qualified
ERROR: LoadError: undefvarerror: params not defined

我可以知道执行详细代码基准测试的最佳方法是什么吗?

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)