-
Notifications
You must be signed in to change notification settings - Fork 4
/
demoprepare.jl
54 lines (47 loc) · 1.56 KB
/
demoprepare.jl
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
using JSON
dhome = ARGS[1]
trgthome = dhome * "demo/"
valfile = dhome * "val.json"
dicfile = dhome * "dic.json"
oclvr = dhome * "CLEVR_v1.0/images/val/"
clvrhome = dhome * "demo/CLEVR_v1.0/"
imgshome = dhome * "demo/CLEVR_v1.0/images/"
valimgs = dhome * "demo/CLEVR_v1.0/images/val/"
function loadFeatures(dhome,set)
feats = reinterpret(Float32,read(open(dhome*set*".bin")))
reshape(feats,(14,14,1024,div(length(feats),200704)))
end
function getdemo(file;part=100)
println("Validation feats are loading...")
valfeats = loadFeatures(dhome,"val")
demofeats = Any[];
println("Validation data are loading...")
data = JSON.parsefile(file)
demo = data[randperm(length(data))[1:part]]
println("Random selection are collecting...")
for d in demo
imgname = d[1]
cp(oclvr*imgname ,valimgs*imgname;remove_destination=true)
id = parse(Int,imgname[end-9:end-4])+1
push!(demofeats,valfeats[:,:,:,id])
end
demofeats = cat(4,demofeats...)
println("Demo feats are writed...")
f = open(trgthome*"demo.bin","w")
write(f,demofeats); close(f)
println("Demo data is writed...")
open(trgthome * "demo.json","w") do f
write(f,json(demo))
end
end
println("Creating demo folders if necessary...")
!isdir(trgthome) && mkdir(trgthome)
!isdir(clvrhome) && mkdir(clvrhome)
!isdir(imgshome) && mkdir(imgshome)
if isdir(valimgs)
rm(valimgs;recursive=true)
end
mkdir(valimgs)
getdemo(valfile)
cp(dicfile,trgthome * "dic.json";remove_destination=true)
run(`tar -cvzf demo.tar.gz $(trgthome)`)