-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Canny
committed
Apr 10, 2017
1 parent
7fc7f26
commit b97e7f7
Showing
4 changed files
with
138 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
val tt = "train"; | ||
|
||
val imagenetroot = "/data/ImageNet/2012resized/"+tt+"/"; | ||
val dataroot = "../../data/ImageNet/"; | ||
val savefname = tt+"/part%04d.fmat.lz4"; | ||
val labelfname = tt+"/label%04d.imat.lz4"; | ||
val namesfname = tt+"/names%04d.csmat.txt"; | ||
val loadtable = loadCSMat(dataroot+tt+".txt"); | ||
|
||
val bsize = 1024; | ||
|
||
val nimgs = loadtable.nrows; | ||
|
||
val fnames = loadtable(?,0); | ||
val alllabels = loadtable(?,1).toIMat; | ||
|
||
val perm = randperm(nimgs); | ||
val mat = zeros(4 \ 256 \ 256 \ bsize); | ||
val labels = izeros(1, bsize); | ||
val names = CSMat(bsize,1); | ||
var i = 0; | ||
var jin = 0; | ||
while (jin < nimgs) { | ||
val todo = math.min(bsize, nimgs - jin); | ||
var j = 0; | ||
while (j < todo && jin < nimgs) { | ||
val indx = perm(jin); | ||
try { | ||
val im = loadImage(imagenetroot+fnames(indx)); | ||
mat(?,?,?,j) = im.toFMat; | ||
labels(0, j) = alllabels(indx); | ||
names(j) = fnames(indx); | ||
j += 1; | ||
} catch { | ||
case e:Exception => println("\nProblem reading %s, continuing" format fnames(indx)); | ||
} | ||
jin += 1; | ||
} | ||
if (j == bsize) { | ||
saveFMat(dataroot+savefname format i, mat); | ||
saveIMat(dataroot+labelfname format i, labels); | ||
saveCSMat(dataroot+namesfname format i, names); | ||
} else { | ||
saveFMat(dataroot+savefname format i, mat.colslice(0,j)); | ||
saveIMat(dataroot+labelfname format i, labels.colslice(0,j)); | ||
saveCSMat(dataroot+namesfname format i, names(0->j,0)); | ||
} | ||
i += 1; | ||
print("."); | ||
} | ||
println(""); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
:silent | ||
|
||
val tt = "train"; | ||
|
||
val dataroot = "../../data/ImageNet/"; | ||
val labelfname = dataroot+tt+"/label%04d.imat.lz4"; | ||
val labelsout = dataroot+tt+"/labels%04d.fmat.lz4"; | ||
|
||
val bsize = 1024; | ||
val nparts = 1252; | ||
|
||
print("\nComputing one-hot labels"); | ||
val omat = zeros(1000,bsize); | ||
val coln = irow(0->bsize) *@ 1000; | ||
for (i <- 0 until nparts) { | ||
val mat = loadIMat(labelfname format i); | ||
omat.clear; | ||
val inds = mat + coln(0,0->mat.ncols); | ||
omat(inds) = 1f; | ||
if (mat.ncols == bsize) { | ||
saveFMat(labelsout format i, omat); | ||
} else { | ||
saveFMat(labelsout format i, omat.colslice(0,mat.ncols)); | ||
} | ||
print("."); | ||
} | ||
println(""); | ||
|
||
:silent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
:silent | ||
|
||
val tt = "train"; | ||
|
||
val dataroot = "../../data/ImageNet/"; | ||
val datafname = dataroot+tt+"/part%04d.fmat.lz4"; | ||
val labelfname = dataroot+tt+"/label%04d.imat.lz4"; | ||
val namesfname = dataroot+tt+"/names%04d.csmat.txt"; | ||
|
||
val bsize = 1024; | ||
val nparts = 1252; | ||
|
||
val triminds = irow(16 -> 240); | ||
val trimcolors = irow(0,1,2); | ||
|
||
var nimgs = 0L; | ||
val msum = dzeros(3\224\224\1); | ||
|
||
print("\nComputing mean"); | ||
val times = zeros(1,4) | ||
for (i <- 0 until nparts) { | ||
tic; | ||
val mat = loadFMat(datafname format i); | ||
val t1 = toc; | ||
val trim = mat(trimcolors, triminds, triminds, ?); | ||
val t2 = toc; | ||
val tmpsum = trim.sum(irow(3)); | ||
val t3 = toc; | ||
msum ~ msum + DMat(tmpsum); | ||
val t4 = toc; | ||
times ~ times + row(t1,t2-t1,t3-t2,t4-t3); | ||
nimgs = nimgs + trim.ncols; | ||
print("."); | ||
} | ||
println(""); | ||
|
||
msum ~ msum / nimgs.toDouble; | ||
val means = FMat(msum); | ||
saveFMat(dataroot+tt+"/means.fmat.lz4", means); | ||
|
||
:silent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters