Compile and forw functions

question

#1

this function is vgg function

vggmodel(x0;weights=0)
x1 = cbf(x0; w = map(Float32,weights["w1_1"]), b = reshape(map(Float32,weights["b1_1"]) ,1,1,size(weights["b1_1"],1),1), out=64)

    x2 = cbf(x1; w = map(Float32,weights["w1_2"]), b = reshape(map(Float32,weights["b1_2"]) ,1,1,size(weights["b1_2"],1),1), out=64)

    x3 = pool(x2; window = 2)

    x4 = cbf(x3; w = map(Float32,weights["w2_1"]), b = reshape(map(Float32,weights["b2_1"]) ,1,1,size(weights["b2_1"],1),1), out=128)

    x5 = cbf(x4; w = map(Float32,weights["w2_2"]), b = reshape(map(Float32,weights["b2_2"]) ,1,1,size(weights["b2_2"],1),1), out=128)

    x6 = pool(x5; window = 2)

    x7 = cbf(x6; w = map(Float32,weights["w3_1"]), b = reshape(map(Float32,weights["b3_1"]) ,1,1,size(weights["b3_1"],1),1), out=256)

    x8 = cbf(x7; w = map(Float32,weights["w3_2"]), b = reshape(map(Float32,weights["b3_2"]) ,1,1,size(weights["b3_2"],1),1), out=256)

    x9 = cbf(x8; w = map(Float32,weights["w3_3"]), b = reshape(map(Float32,weights["b3_3"]) ,1,1,size(weights["b3_3"],1),1), out=256)

    x10 = pool(x9; window = 2)

    x11 = cbf(x10; w = map(Float32,weights["w4_1"]), b = reshape(map(Float32,weights["b4_1"]) ,1,1,size(weights["b4_1"],1),1), out=512)

    x12 = cbf(x11; w = map(Float32,weights["w4_2"]), b = reshape(map(Float32,weights["b4_2"]) ,1,1,size(weights["b4_2"],1),1), out=512)

    x13 = cbf(x12; w = map(Float32,weights["w4_3"]), b = reshape(map(Float32,weights["b4_3"]) ,1,1,size(weights["b4_3"],1),1), out=512)

    x14 = pool(x13; window = 2)

    x15 = cbf(x14;w = map(Float32,weights["w5_1"]), b = reshape(map(Float32,weights["b5_1"]) ,1,1,size(weights["b5_1"],1),1), out=512)

    x16 = cbf(x15; w = map(Float32,weights["w5_2"]), b = reshape(map(Float32,weights["b5_2"]) ,1,1,size(weights["b5_2"],1),1), out=512)

    x17 = cbf(x16; w = map(Float32,weights["w5_3"]), b = reshape(map(Float32,weights["b5_3"]) ,1,1,size(weights["b5_3"],1),1), out=512)

    x18 = pool(x17; window = 2)

return cbf(x18;w = map(Float32,weights["w6"]), b = reshape(map(Float32,weights["b6"]) ,1,1,size(weights["b6"],1),1), f=:relu, p=0)

    #x20 = cbf(x19; w= w77, b=b77, f=:relu, out=4096, p=0)

The “file” variable contains parameter pretrained. I hope use compile function to initiallize the vgg with the pretrained parameter. At last, i want to use forw function to run the vgg with a series of picture in xdevZeroPad. so i suggest we can add the two functions to achieve them.

file = matread("vgg-verydeep-16.mat") global vgg = compile(:vgg_model; weights=file) ypred = forw(vgg, xdevZeroPad[:,:,:,item:item+nbatch-1]; trn=false)