Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
237 commits
Select commit Hold shift + click to select a range
a24c896
add poly lr schedule
yiheng Sep 25, 2016
7d1f622
use larger iterations
yiheng Sep 26, 2016
ce81bcb
set learning rate to 0 if iteration number is greater than maxIteration
yiheng Sep 27, 2016
9d81a12
print learning rate and iteration number in poly
yiheng Sep 27, 2016
4dded82
update pom.xml
qiuxin2012 Sep 28, 2016
58e1e3e
Merge pull request #26 from qiuxin2012/master
yiheng-wang-intel Sep 29, 2016
c712595
turn module into evaluation mode when test
yiheng Oct 7, 2016
edafc8b
fix code format issue
yiheng Oct 7, 2016
0e9ca8b
Merge pull request #29 from yiheng/poly_support
yiheng-wang-intel Oct 7, 2016
ecaae66
add Tensor and TensorMath comments
ShuhanYan Oct 10, 2016
5126f34
Merge pull request #32 from yansh0625/comments
psyyz10 Oct 12, 2016
18fadb2
Improve LRN Perfomance
yiheng Sep 22, 2016
950ad37
Rename LRN layer to SpatialCrossMapLRN
yiheng Sep 25, 2016
e1e48b4
Compare crossmap LRN result with torch
yiheng Sep 25, 2016
2198cc8
Compare crossmap LRN result with torch
yiheng Sep 25, 2016
0098f80
Compare LRN result with torch
yiheng Sep 25, 2016
4af9492
Compare LRN result with torch
yiheng Sep 25, 2016
9a1b2b4
Use random generator in dataset shuffle
yiheng Sep 25, 2016
7ed7e55
change softmax name to loss in alexnet
yiheng Sep 26, 2016
73263c8
use new models in TestModelParallel
yiheng Sep 26, 2016
2999cc1
parallize batchnormalization
yiheng Sep 26, 2016
e00a0e0
improve concat perf
yiheng Sep 26, 2016
5bb66d6
improve concat perf
yiheng Sep 26, 2016
bae85c0
improve concat perf
yiheng Sep 26, 2016
92a9b43
add Math Operation
ShuhanYan Sep 27, 2016
5195707
add Math perform test
ShuhanYan Sep 27, 2016
cd39d60
add jni func
ShuhanYan Sep 27, 2016
0e28e12
add jni func
ShuhanYan Sep 27, 2016
2911bcf
add Unit Test
ShuhanYan Sep 28, 2016
a8ccf23
remove performtest
ShuhanYan Sep 28, 2016
170063a
improve concat perf
yiheng Sep 26, 2016
ced129a
don't convert when conv kernel is 1x1
yiheng Sep 28, 2016
fdba328
print concat overhead in the perf profiling
yiheng Sep 28, 2016
a1b94e5
don't backward gradient for the first layer
yiheng Sep 28, 2016
4918755
fix break uts
yiheng Sep 28, 2016
4484e95
fix code format issue
yiheng Sep 28, 2016
1ebc2f6
Add multimodel perf test
yiheng Sep 30, 2016
014d151
refactor data preprocess code
zhangxiaoli73 Sep 13, 2016
6fb15ef
fix opened files too many bug
yiheng Oct 13, 2016
dd5fb30
resolve ImageIO
zhangxiaoli73 Oct 14, 2016
31762a8
Merge pull request #7 from zhangxiaoli73/dataset3
yiheng-wang-intel Oct 14, 2016
0906985
fix a bug that cause CNN MNIST not converge to 99%
yiheng Oct 14, 2016
1ccc0d9
try to init epoch and neval number with exsited value in state
yiheng Oct 14, 2016
7223c9e
adjust cifar10 hyper parameter
yiheng Oct 18, 2016
c0c7128
use double when calculate mean sum
yiheng Oct 18, 2016
be3ed07
Merge pull request #34 from yiheng/dataset
yiheng-wang-intel Oct 18, 2016
b18c069
bug fix for gemm
qiuxin2012 Oct 19, 2016
a4923a3
1. convert image to seq file 2. add mkl_rt to linkerEndOption
zhangxiaoli73 Oct 19, 2016
57a4c50
1. convert image to seq file 2. add mkl_rt to linkerEndOption
zhangxiaoli73 Oct 19, 2016
ac27813
adjust indent for DenseTensorBLAS
qiuxin2012 Oct 19, 2016
112df42
Unit test for DenseTensorBLAS.gemm
qiuxin2012 Oct 19, 2016
4565473
Merge pull request #35 from qiuxin2012/pvanet
yiheng-wang-intel Oct 20, 2016
9673107
refactor the code to make it support both table and tensor as layer i…
psyyz10 Oct 20, 2016
943db7a
fix code style errors
psyyz10 Oct 20, 2016
6a8cc30
refactor the code to make it support both table and tensor as layer i…
psyyz10 Oct 20, 2016
47144be
fix code style errors
psyyz10 Oct 20, 2016
e4a9935
uncomment getTimes() in Concat.scala
psyyz10 Oct 20, 2016
ceebfab
fix conflicts
psyyz10 Oct 21, 2016
d7512df
merge with quixin's code
psyyz10 Oct 21, 2016
31af891
use another property to control dl engine core number
yiheng Oct 21, 2016
238544b
use fixed threading pool in multiple model training
yiheng Oct 21, 2016
e5a6148
refactor the code to make it support both table and tensor as layer i…
psyyz10 Oct 20, 2016
3c51db6
Merge branch 'master' of https://github.com/psyyz10/spark-dl
psyyz10 Oct 21, 2016
7efeedd
fix broken unittest
yiheng Oct 21, 2016
48b3869
Merge pull request #37 from yiheng/master
qiuxin2012 Oct 21, 2016
6f6c055
spatial full convolution
qiuxin2012 Oct 20, 2016
bff2400
spatial full convolution code clean up
qiuxin2012 Oct 20, 2016
006a4c9
add bilinear init method for spatial full convolution
qiuxin2012 Oct 21, 2016
534a5df
Merge pull request #36 from qiuxin2012/pvanet
yiheng-wang-intel Oct 21, 2016
3b676b6
bug fix for DenseTensorMath cmul and cdiv
qiuxin2012 Oct 21, 2016
81439a6
add some missed file for Power
qiuxin2012 Oct 21, 2016
6433de6
add two unit test for power
qiuxin2012 Oct 21, 2016
ed2877c
add some comment
qiuxin2012 Oct 21, 2016
298c41d
some small fix for unit test failed
qiuxin2012 Oct 21, 2016
ecfd892
Merge pull request #42 from qiuxin2012/pvanet
qiuxin2012 Oct 21, 2016
e82ee9a
add some math operation
ShuhanYan Oct 24, 2016
9eeee5f
fic conflict
ShuhanYan Oct 24, 2016
1b0086a
Merge pull request #39 from psyyz10/master
psyyz10 Oct 24, 2016
da05313
checkin abs and add layer
zhangxiaoli73 Oct 21, 2016
82614a4
fix bugs
ShuhanYan Oct 24, 2016
ab26139
fix a scala-style error: a too long line of code
psyyz10 Oct 24, 2016
0c62ffd
1.some changes for abs and add layer according to pr 2. checkin AbsCr…
zhangxiaoli73 Oct 24, 2016
0064028
fix a scala-style error: a too long line of code
psyyz10 Oct 24, 2016
8ed1f42
Make sub-models cast to Model[Activities, Activities, T] in the add p…
psyyz10 Oct 25, 2016
21b3143
Merge branch 'master' of fork origin reporsitory
psyyz10 Oct 25, 2016
7aa1eab
require contigous
zhangxiaoli73 Oct 26, 2016
84bead8
Merge pull request #47 from psyyz10/master
yiheng-wang-intel Oct 26, 2016
8b37393
CAdd module
qiuxin2012 Oct 25, 2016
46d77d6
CMul module and some other codes
qiuxin2012 Oct 26, 2016
44efa92
change on function equals and hashcode
qiuxin2012 Oct 26, 2016
2a907c6
add SmoothL1Criterion code and test'
Oct 26, 2016
e7bf50e
Merge pull request #44 from qiuxin2012/master
qiuxin2012 Oct 26, 2016
9aa5b28
fix comflict
ShuhanYan Oct 27, 2016
d4650f7
Merge pull request #49 from zhangxiaoli73/master
yiheng-wang-intel Oct 27, 2016
7721ae5
remove println
ShuhanYan Oct 27, 2016
7601161
fix conflict
ShuhanYan Oct 27, 2016
9726688
fix code style bug
ShuhanYan Oct 27, 2016
fadce4b
update coding style
Oct 27, 2016
79e955f
Merge pull request #43 from yansh0625/work
yiheng-wang-intel Oct 27, 2016
ce5fe9a
optimise code
Oct 28, 2016
1002f22
fix null bug
Oct 28, 2016
f03ad8f
fix test bug
Oct 28, 2016
648dde0
Support both Table and Tensor as input or output of criterions
psyyz10 Oct 27, 2016
83e7392
Merge with New version code in upstream master
psyyz10 Oct 27, 2016
49c28b1
Add Exp layer
psyyz10 Oct 27, 2016
c11c270
Fix a bug in Criterion interface, the generic type should be [A, T] r…
psyyz10 Oct 27, 2016
4f2c323
Add backward test to exp layer
psyyz10 Oct 31, 2016
ad64ff2
fix conflict with upstream master
psyyz10 Nov 1, 2016
819cd84
Merge pull request #50 from SeaOfOcean/nn
yiheng-wang-intel Nov 1, 2016
88d4717
Merge pull request #53 from psyyz10/master
yiheng-wang-intel Nov 2, 2016
bf21a4c
update Readme
yiheng Nov 2, 2016
a0368ca
Implement and test RReLU layer
psyyz10 Nov 1, 2016
bbdf356
optimize code to meet code review
psyyz10 Nov 2, 2016
5a95975
fix a bug in Container evaluate()
psyyz10 Nov 2, 2016
4c066c4
ConcatTable CAddTable and Identity
qiuxin2012 Nov 1, 2016
c1c5f55
some changes about CAddTable and ConcatTable
qiuxin2012 Nov 3, 2016
f309486
Merge pull request #58 from psyyz10/RReLU
psyyz10 Nov 3, 2016
689c067
add Bilinear layer and convert java.map to scala.map
zhangxiaoli73 Oct 28, 2016
9841c91
some modify of Bilinear
zhangxiaoli73 Nov 1, 2016
419f64d
resolve confilicts
zhangxiaoli73 Nov 2, 2016
e0342d2
delete T() init
zhangxiaoli73 Nov 3, 2016
7ce70b4
change to use select
zhangxiaoli73 Nov 3, 2016
e387c37
add nexus release to pom
ShuhanYan Nov 4, 2016
4d805f1
fix imagenet local code
yiheng Oct 18, 2016
23cf0f5
fix localoptimizer can't handle some trigger correctly
yiheng Oct 20, 2016
7f61cf2
dataset code refactor
yiheng Oct 24, 2016
bf87f6b
fix compile error from code merge
yiheng Nov 2, 2016
0681f9a
code refactor of dataset
yiheng Nov 3, 2016
c790037
add back momentum in ImageNet training
yiheng Nov 4, 2016
0328836
support for mkl dnn api, which is migrated from WebscaleML.
i8run Sep 20, 2016
27c71e9
delete the unused codes
i8run Sep 20, 2016
3886cc3
support for cancel the data conversion between two mkl layers
i8run Sep 20, 2016
0f2bf03
fix the codestyle of scala source code
i8run Sep 20, 2016
90a77ed
add input size and strides to pooling
i8run Sep 24, 2016
8c7aaad
add concat support
i8run Sep 24, 2016
da42265
change the api of convolution to the same as nn
i8run Sep 24, 2016
b9a51bf
add support for sum
i8run Sep 24, 2016
cb1f9aa
migrate the openmp manager from intel caffe
i8run Sep 27, 2016
70c5f65
cancel the conversion between two mkl layers
i8run Oct 6, 2016
dfbc658
fix the error of reset method
i8run Oct 8, 2016
d43c2ab
fix the concat check failed bug and add two testcases for Concat
i8run Oct 8, 2016
d5668e1
Change updateGradInput to backward in concat testcase.
i8run Oct 9, 2016
c3fb8a2
Fix the bug of uncorrect result of gradient input of SpatialConvolution.
i8run Oct 10, 2016
6d62c74
testcases for concat
i8run Oct 10, 2016
09bd02c
add a constant initlize method.
i8run Oct 10, 2016
671186b
initlize the layout pointer
i8run Oct 12, 2016
aa4c1ae
Corretness verify.
i8run Oct 19, 2016
f35daa7
Fix some bugs and add some tests compared with IntelCaffe w/ MKL-DNN.
i8run Nov 4, 2016
fe442dc
convergence test with Cifar and AlexNet, Currently it can not converge.
i8run Nov 4, 2016
28de43e
adjust cache path
yiheng Nov 4, 2016
911e273
fix testcase because of new type and openmp for c++11
i8run Nov 8, 2016
b392b10
add static-intel to native pom.xml
qiuxin2012 Nov 8, 2016
7921a8f
Implement and test HardTanh
psyyz10 Nov 3, 2016
fea8450
Make HardTanh update parallel
psyyz10 Nov 3, 2016
9c47ff8
Implement and test Clamp and ReLu6
psyyz10 Nov 8, 2016
c049b19
Implement Copy layer
psyyz10 Oct 28, 2016
7e852fb
fix a style error
psyyz10 Nov 3, 2016
d271ab7
Implement and test Log layer
psyyz10 Oct 31, 2016
b27345d
fix a style error
psyyz10 Nov 3, 2016
73a69f7
fix a test bug
psyyz10 Nov 8, 2016
de881f8
SoftMax
qiuxin2012 Nov 3, 2016
d13f919
parallel SoftMax
qiuxin2012 Nov 3, 2016
32f0891
SoftMin
qiuxin2012 Nov 4, 2016
e6f5e97
add toString to SoftMax and SoftMin
qiuxin2012 Nov 4, 2016
04783f1
add input distribution option for perf.
i8run Nov 10, 2016
a829f66
Implement and test LogSigmoid
psyyz10 Oct 31, 2016
2f6d17e
Optimise some code according to the code review
psyyz10 Nov 8, 2016
33605d2
Add layer comment to LogSigmoid
psyyz10 Nov 8, 2016
e316f4f
Implement and test HardShrink
psyyz10 Nov 6, 2016
4b782b3
Add JavaDoc to HardShrink and meet code reviews
psyyz10 Nov 9, 2016
2269af0
fix for Batchnormalization's gradBias and gradWeight
qiuxin2012 Nov 14, 2016
276f2cc
Implement and test LeakyReLU
psyyz10 Nov 3, 2016
d8cfe0b
Add JavaDoc to LeakyReLU and meet code reviews
psyyz10 Nov 9, 2016
7af0bda
Fix a scala style error
psyyz10 Nov 13, 2016
1090338
add CMul,CMax,CMin,CSub Table layer
zhangxiaoli73 Nov 4, 2016
bd74921
hide apply
zhangxiaoli73 Nov 4, 2016
0c69a60
CosineEmbeddingCriterion
zhangxiaoli73 Nov 7, 2016
b922a2c
add some comments
zhangxiaoli73 Nov 9, 2016
f5a9eaf
add comments for previous layers
zhangxiaoli73 Nov 11, 2016
ebf3868
SoftSign
qiuxin2012 Nov 4, 2016
f5b2da6
add javadoc
qiuxin2012 Nov 14, 2016
839915d
ParallelCriterion
qiuxin2012 Nov 4, 2016
4954adf
add recursiveapply for table
qiuxin2012 Nov 14, 2016
2dc7069
Implement and test ELU layer
psyyz10 Nov 6, 2016
f61ba40
Add todo comment to ELU
psyyz10 Nov 9, 2016
4484175
Fix a scala style error
psyyz10 Nov 13, 2016
f42cc56
SoftPlus and SoftShrink
qiuxin2012 Nov 7, 2016
445397a
add javadoc
qiuxin2012 Nov 14, 2016
94e653b
Implement and test GradientReversal layer
psyyz10 Nov 6, 2016
d99a260
Add JavaDoc to GradientReversal and meet code reviews
psyyz10 Nov 9, 2016
558f184
fix a scala style error
psyyz10 Nov 13, 2016
da31649
Sqrt Square
qiuxin2012 Nov 7, 2016
1294cf7
Replicate
qiuxin2012 Nov 8, 2016
802f271
add javadoc
qiuxin2012 Nov 15, 2016
13e6e0c
add toString to Power
qiuxin2012 Nov 15, 2016
abf9b8d
SpatialDilatedConvolution
qiuxin2012 Nov 2, 2016
c28ca5c
some changes
qiuxin2012 Nov 4, 2016
6b67839
add java doc
qiuxin2012 Nov 14, 2016
41282d0
SpatialFullConv table input support
qiuxin2012 Nov 14, 2016
a39eb8f
delete alpha channel exception and add unit test
zhangxiaoli73 Nov 11, 2016
94c9d23
Implement and test nn.Sum layer
psyyz10 Nov 7, 2016
357c430
Implement and test Mean layer
psyyz10 Nov 7, 2016
86bb188
Add JavaDoc to Sum and Mean layers and meet code reviews
psyyz10 Nov 9, 2016
f409389
Impelement and test nn.DotProduct
psyyz10 Nov 8, 2016
01ee95c
Add JavaDoc to DotProduct layer
psyyz10 Nov 9, 2016
8d1b518
Implement and test MapTable
psyyz10 Nov 9, 2016
6e148de
Add class comment as description for the MapTable
psyyz10 Nov 9, 2016
dae1a8c
Add JavaDoc to MapTable
psyyz10 Nov 9, 2016
58fda2f
Implement and test Select
psyyz10 Nov 9, 2016
20b02ca
Implement and test TanhShrink
psyyz10 Nov 9, 2016
27bf2aa
Add JavaDoc to Select and TanhShrink and meet code reviews
psyyz10 Nov 9, 2016
eff2df7
add distribution of input
i8run Nov 16, 2016
0867555
support for mkl dnn api, which is migrated from WebscaleML.
i8run Sep 20, 2016
7a90683
delete the unused codes
i8run Sep 20, 2016
42618cd
support for cancel the data conversion between two mkl layers
i8run Sep 20, 2016
ca26540
fix the codestyle of scala source code
i8run Sep 20, 2016
11b1fff
add input size and strides to pooling
i8run Sep 24, 2016
29b3ce9
add concat support
i8run Sep 24, 2016
0dd1bcc
change the api of convolution to the same as nn
i8run Sep 24, 2016
67d66c8
add support for sum
i8run Sep 24, 2016
7eb5ec2
migrate the openmp manager from intel caffe
i8run Sep 27, 2016
874ae48
cancel the conversion between two mkl layers
i8run Oct 6, 2016
e95fa93
fix the error of reset method
i8run Oct 8, 2016
f0e8a01
fix the concat check failed bug and add two testcases for Concat
i8run Oct 8, 2016
c124364
Change updateGradInput to backward in concat testcase.
i8run Oct 9, 2016
b53d959
Fix the bug of uncorrect result of gradient input of SpatialConvolution.
i8run Oct 10, 2016
82d91d7
testcases for concat
i8run Oct 10, 2016
081e611
add a constant initlize method.
i8run Oct 10, 2016
cad3116
initlize the layout pointer
i8run Oct 12, 2016
5f34308
Corretness verify.
i8run Oct 19, 2016
0dfad15
Fix some bugs and add some tests compared with IntelCaffe w/ MKL-DNN.
i8run Nov 4, 2016
1216741
convergence test with Cifar and AlexNet, Currently it can not converge.
i8run Nov 4, 2016
e1fea3b
fix testcase because of new type and openmp for c++11
i8run Nov 8, 2016
b3aa51e
add input distribution option for perf.
i8run Nov 10, 2016
a30f49a
add distribution of input
i8run Nov 16, 2016
a2bdf30
Add GoogLeNet v1 test case. And modify some implementation of AlexNet.
i8run Nov 18, 2016
dd8be7a
Merge branch 'master' of https://github.com/i8run/spark-dl
i8run Nov 20, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ project/plugins/project/

# other
*.txt
*.csv
*.swp # vim swap file
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
Deep learning library for Apache Spark
#BigDL

A scalable deep learning library for Apache Spark.

Here's the summary of core features:
* a powerful N-dimensional array
* lots of math and data manipulating operations
* rich neural network layers
* effecient distributed numeric optimization routines on Apache Spark
* powered by MKL and MKL DNN, fast and optmized on Intel hardware platforms

##How to build
###Linux
1. Download [Intel MKL](https://software.intel.com/en-us/intel-mkl) and install it in your linux box
2. Prepare MKL build environment<br> <code>source PATH_TO_MKL/bin/mklvars.sh &#60;arch&#62;</code><br> The **&#60;arch&#62;** can be *ia32*, *intel64*, or *mic*, which depends on your system.
3. Build project<br> <code>mvn clean package -DskipTests -P mkl</code>

##Example
* MNIST example
* Cifar10 example
* Imagenet example
9 changes: 7 additions & 2 deletions dl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sparkdl-parent_0.1</artifactId>
<groupId>com.intel.analytics.sparkdl</groupId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.0-dnn-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -19,6 +19,11 @@
</properties>

<dependencies>
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
Expand All @@ -32,7 +37,7 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.intel.analytics.dllib.mkl</groupId>
<groupId>com.intel.analytics.sparkdl.mkl</groupId>
<artifactId>mkl-java_0.1</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion dl/scalastyle_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ You can also disable only one rule, by specifying its rule id, as specified in:

<check level="error" class="org.scalastyle.scalariform.DeprecatedJavaChecker" enabled="true"></check>

<check level="error" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"></check>
<check customId="noSpaceBeforeLeftBracket" level="error" class="org.scalastyle.scalariform.NoWhitespaceBeforeLeftBracketChecker" enabled="true"></check>
<check level="error" class="org.scalastyle.scalariform.NoWhitespaceAfterLeftBracketChecker" enabled="true"></check>

<check customId="methodName" level="error" class="org.scalastyle.scalariform.MethodNamesChecker" enabled="true">
Expand Down
72 changes: 72 additions & 0 deletions dl/src/main/scala/com/intel/analytics/sparkdl/dataset/Cifar.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.intel.analytics.sparkdl.dataset

import java.nio.file.{Files, Path, Paths}

import com.intel.analytics.sparkdl.models.cifar.VggLike
import com.intel.analytics.sparkdl.nn.ClassNLLCriterion
import com.intel.analytics.sparkdl.optim.SGD.EpochStep
import com.intel.analytics.sparkdl.optim.{LocalOptimizer, SGD, Top1Accuracy, Trigger}
import com.intel.analytics.sparkdl.utils.T
import scopt.OptionParser

object Cifar10Local {
case class Cifar10LocalParam(
folder: String = "./",
net: String = "vgg"
)

private val parser = new OptionParser[Cifar10LocalParam]("Spark-DL Cifar10 Local Example") {
head("Spark-DL Cifar10 Local Example")
opt[String]('f', "folder")
.text("where you put the Cifar10 data")
.action((x, c) => c.copy(folder = x))
}

def main(args: Array[String]) {
parser.parse(args, new Cifar10LocalParam()).map(param => {
val trainDataSource = new CifarDataSource(Paths.get(param.folder + "/train"), looped = true)
val validationDataSource = new CifarDataSource(Paths.get(param.folder + "/val"),
looped = false)
val arrayToImage = ArrayByteToRGBImage()
val normalizer = RGBImageNormalizer(trainDataSource -> arrayToImage)
val toTensor = new RGBImageToTensor(batchSize = 128)

val optimizer = new LocalOptimizer[Float](
data = trainDataSource -> arrayToImage -> normalizer -> toTensor,
validationData = validationDataSource -> arrayToImage -> normalizer -> toTensor,
model = VggLike[Float](classNum = 10),
criterion = new ClassNLLCriterion[Float](),
optimMethod = new SGD[Float](),
state = T(
"learningRate" -> 0.01,
"weightDecay" -> 0.0005,
"momentum" -> 0.9,
"dampening" -> 0.0,
"learningRateSchedule" -> EpochStep(25, 0.5)
),
endWhen = Trigger.maxEpoch(90)
)
optimizer.setValidationTrigger(Trigger.everyEpoch)
optimizer.addValidation(new Top1Accuracy[Float])

optimizer.optimize()
})
}
}
121 changes: 121 additions & 0 deletions dl/src/main/scala/com/intel/analytics/sparkdl/dataset/ConvertSeq.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intel.analytics.sparkdl.dataset

import java.io.IOException
import java.nio.ByteBuffer
import java.nio.file.Paths

import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs.Path
import org.apache.hadoop.io.{SequenceFile, Text}
import scopt.OptionParser

object ConvertSeq {

case class ConvertSeqParams(
folder: String = "./",
outputSeq: String = "./",
parallel: Int = 1,
buffer : Int = 256,
dataSetType: String = "ImageNet"
)

private val parser = new OptionParser[ConvertSeqParams]("Spark-DL Convert Seq") {
head("Convert Image Files to Hadoop Sequential Files")
opt[String]('f', "folder")
.text("where you put the dataset")
.action((x, c) => c.copy(folder = x))
opt[String]('o', "outputSeq")
.text("outputSeq folder")
.action((x, c) => c.copy(outputSeq = x))
opt[Int]('p', "parallel")
.text("parallel num")
.action((x, c) => c.copy(parallel = x))
opt[Int]('b', "buffer")
.text("buffer size")
.action((x, c) => c.copy(buffer = x))
opt[String]('d', "dataSetType")
.text("dataset type")
.action((x, c) => c.copy(dataSetType = x))
}

def main(args: Array[String]): Unit = {
parser.parse(args, new ConvertSeqParams()).map(param => {
param.dataSetType match {
case "ImageNet" =>
val dataSource = new ImageNetDataSource(Paths.get(param.folder), looped = false)
val pathToImage = PathToRGBImage(256)
val worker = new Worker(dataSource -> pathToImage, param.parallel)
worker.process(param.outputSeq)
case "Cifar-10" =>
val dataSource = new CifarDataSource(Paths.get(param.folder), looped = false)
val arrayToImage = ArrayByteToRGBImage()
val worker = new Worker(dataSource -> arrayToImage, param.parallel)
worker.process(param.outputSeq)
case _ => throw new UnsupportedOperationException(s"Only ImageNet/Cifar-10 supported")
}
})
}
}

class Worker(dataSet: DataSource[RGBImage], parallel: Int) {

def process(target: String): Unit = {
var i = 0
var file = s"${target}-seq"
val writer = new Writer(file)
while(dataSet.hasNext) {
val data = dataSet.next()
val imageKey = s"${data.label()}-${i}"
println(s"write ${imageKey}")
writer.write(imageKey, RGBImage.convertToByte(data.content, data.width(), data.height()),
data.width(), data.height())
i += 1
}
writer.close()
}
}

class Writer @throws[IOException]
(val seqFilePath: String) {
private val conf: Configuration = new Configuration
val path = new Path(seqFilePath)
val writer = SequenceFile.createWriter(conf, SequenceFile.Writer.file(path),
SequenceFile.Writer.keyClass(classOf[Text]), SequenceFile.Writer.valueClass(classOf[Text]))
var preBuffer: ByteBuffer = ByteBuffer.allocate(4 * 2)

@throws[Exception]
def write(imageKey: String, img: Array[Byte], width: Int, height: Int) {
preBuffer.putInt(width)
preBuffer.putInt(height)
val data: Array[Byte] = new Array[Byte](preBuffer.capacity + img.length)
System.arraycopy(preBuffer.array, 0, data, 0, preBuffer.capacity)
System.arraycopy(img, 0, data, preBuffer.capacity, img.length)
preBuffer.clear
writer.append(new Text(imageKey), new Text(data))
}

def close() {
try {
writer.close()
} catch {
case e: IOException =>
e.printStackTrace()
}
}
}
Loading