Skip to content

Commit 0b231f4

Browse files
committed
Knet1.0.1 - Compat
1 parent cf25666 commit 0b231f4

16 files changed

+2281
-482
lines changed

Manifest.toml

+492
Large diffs are not rendered by default.

Project.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[deps]
2+
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
3+
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
4+
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
5+
Knet = "1902f260-5fb4-5aff-8c31-6271790ab950"
6+
Tqdm = "a73858fe-bd08-11e8-065c-3dfff236a6cd"

demoprepare.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using JSON,JLD
1+
using JSON
22
dhome = ARGS[1]
33
trgthome = dhome * "demo/"
44
valfile = dhome * "val.json"
@@ -14,14 +14,14 @@ function loadFeatures(dhome,set)
1414
end
1515

1616
function getdemo(file;part=100)
17-
info("Validation feats are loading...")
17+
println("Validation feats are loading...")
1818
valfeats = loadFeatures(dhome,"val")
1919
demofeats = Any[];
20-
info("Validation data are loading...")
20+
println("Validation data are loading...")
2121
data = JSON.parsefile(file)
2222
demo = data[randperm(length(data))[1:part]]
2323

24-
info("Random selection are collecting...")
24+
println("Random selection are collecting...")
2525
for d in demo
2626
imgname = d[1]
2727
cp(oclvr*imgname ,valimgs*imgname;remove_destination=true)
@@ -30,17 +30,17 @@ function getdemo(file;part=100)
3030
end
3131
demofeats = cat(4,demofeats...)
3232

33-
info("Demo feats are writed...")
33+
println("Demo feats are writed...")
3434
f = open(trgthome*"demo.bin","w")
3535
write(f,demofeats); close(f)
3636

37-
info("Demo data is writed...")
37+
println("Demo data is writed...")
3838
open(trgthome * "demo.json","w") do f
3939
write(f,json(demo))
4040
end
4141
end
4242

43-
info("Creating demo folders if necessary...")
43+
println("Creating demo folders if necessary...")
4444
!isdir(trgthome) && mkdir(trgthome)
4545
!isdir(clvrhome) && mkdir(clvrhome)
4646
!isdir(imgshome) && mkdir(imgshome)

demosetup.jl

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
# TO-DO Julia7 dependency installment
2-
# if ENV["HOME"] == "/mnt/juliabox"
3-
# Pkg.dir(path...)=joinpath("/home/jrun/.julia/v0.6",path...)
4-
# else
5-
# for p in ("Knet","JLD","JSON","Images") # ,"WordTokenizers")
6-
# Pkg.installed(p) == nothing && Pkg.add(p)
7-
# end
8-
# end
91
server="ai.ku.edu.tr/"
102
if !isdir("data/demo")
113
println("Downloading sample questions and images from CLEVR dataset...")
@@ -17,3 +9,4 @@ if !isfile("models/macnet.jld2")
179
println("Downloading pre-trained model from our servers...")
1810
download(server*"models/mac-network/macnet.jld2","models/macnet.jld2")
1911
end
12+
println("Demo setup is completed")

extract_features.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ function extract(dhome,set,params;atype=Array{Float32})
5555
end
5656

5757
function extract_features(dhome)
58-
atype = gpu()<0 ? Array{Float32}:KnetArray{Float32}
58+
atype = gpu()<0 ? Array{Float32} : KnetArray{Float32}
5959
params = loadparams(atype)
60-
info("Extracting training features")
60+
println("Extracting training features")
6161
extract(dhome,"train",params;atype=atype)
62-
info("Extracting validation features")
62+
println("Extracting validation features")
6363
extract(dhome,"val",params;atype=atype)
6464
end

job.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/sh
22
#SBATCH --partition=ai
3+
#SBATCH --account=ai
34
#SBATCH --gres=gpu:1
45
#SBATCH --time=56:00:00
56
#SBATCH --nodes=1
@@ -8,5 +9,5 @@
89
#SBATCH --job-name="clevr"
910
#SBATCH --output=clevr.out
1011
#SBATCH --error=clevr.error
11-
12-
julia train.jl src/macnet.jl configs/config2.jl
12+
#SBATCH --nodelist=dy02
13+
julia train.jl src/main.jl configs/config2.jl

preprocess.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using JSON, WordTokenizers, ProgressMeter
22

33
function processquestions(dhome, set; word_dic=Dict(), answer_dic=Dict())
4-
info("original data is loading")
4+
println("original data is loading")
55
data = JSON.parsefile(joinpath(dhome,"questions","CLEVR_$(set)_questions.json"))
6-
info("parsing starts...")
6+
println("parsing starts...")
77
result = []
88
p = Progress(length(data["questions"]))
99
for question in data["questions"]
@@ -29,9 +29,9 @@ function preprocess(args)
2929
wdic = dics["word_dic"]
3030
adic = dics["answer_dic"]
3131
end
32-
info("Parsing training questions...")
32+
println("Parsing training questions...")
3333
processquestions(root, "train";word_dic=wdic, answer_dic=adic)
34-
info("Parsing validation questions...")
34+
println("Parsing validation questions...")
3535
processquestions(root, "val" ;word_dic=wdic, answer_dic=adic)
3636

3737
open("data/dic.json", "w") do f

requirements.jl

-7
This file was deleted.

src/loss.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ end
4545
# target probabilities, q is estimated probabilities. Read left column
4646
# down, right column (loss gradients) back up.
4747
48-
# x dx = -p + qz/z = -p + exp(logq)
49-
# xmax = max(x,1) -sum(db)=0
50-
# logqz = x .- xmax -p + qz/z
51-
# qz = exp(logqz) rep(1/z)
52-
# z = sum(qz,1) 1/z
53-
# logz = log(z) sum(p)=1
54-
# logq = logqz.-logz -p
55-
# plogq = p .* logq -1
56-
# loss = -sum(plogq) 1
48+
# xdx = -p + qz/z = -p + exp(logq)
49+
# xmax = max(x,1)-sum(db)=0
50+
# logqz = x .- xmax-p + qz/z
51+
# qz = exp(logqz)rep(1/z)
52+
# z = sum(qz,1)1/z
53+
# logz = log(z)sum(p)=1
54+
# logq = logqz.-logz-p
55+
# plogq = p .* logq-1
56+
# loss = -sum(plogq)1
5757
5858
# We keep the old implementation _logp for CPU arrays, slow cases and
5959
# cases of d not handled by cudnn.

0 commit comments

Comments
 (0)