1- package com .baeldung .deeplearning4j .cnn . domain . network ;
1+ package com .baeldung .deeplearning4j .cnn ;
22
3- import com .baeldung .deeplearning4j .cnn .service .dataset .IDataSetService ;
43import lombok .extern .slf4j .Slf4j ;
54import org .deeplearning4j .eval .Evaluation ;
65import org .deeplearning4j .nn .api .OptimizationAlgorithm ;
1716import java .util .stream .IntStream ;
1817
1918@ Slf4j
20- public class CnnModel {
19+ class CnnModel {
2120
2221 private final IDataSetService dataSetService ;
2322
24- private MultiLayerNetwork network ;
23+ private final MultiLayerNetwork network ;
2524
2625 private final CnnModelProperties properties ;
2726
28- public CnnModel (IDataSetService dataSetService , CnnModelProperties properties ) {
27+ CnnModel (IDataSetService dataSetService , CnnModelProperties properties ) {
2928
3029 this .dataSetService = dataSetService ;
3130 this .properties = properties ;
@@ -52,17 +51,17 @@ public CnnModel(IDataSetService dataSetService, CnnModelProperties properties) {
5251 network = new MultiLayerNetwork (configuration );
5352 }
5453
55- public void train () {
54+ void train () {
5655 network .init ();
5756 int epochsNum = properties .getEpochsNum ();
5857 IntStream .range (1 , epochsNum + 1 ).forEach (epoch -> {
59- log .info (String . format ( "Epoch %d?%d " , epoch , epochsNum ) );
58+ log .info ("Epoch {} / {} " , epoch , epochsNum );
6059 network .fit (dataSetService .trainIterator ());
6160 });
6261 }
6362
64- public Evaluation evaluate () {
65- return network .evaluate (dataSetService .testIterator ());
63+ Evaluation evaluate () {
64+ return network .evaluate (dataSetService .testIterator ());
6665 }
6766
6867 private ConvolutionLayer conv5x5 () {
@@ -84,7 +83,7 @@ private SubsamplingLayer pooling2x2Stride2() {
8483 }
8584
8685 private ConvolutionLayer conv3x3Stride1Padding2 () {
87- return new ConvolutionLayer .Builder (3 , 3 )
86+ return new ConvolutionLayer .Builder (3 , 3 )
8887 .nOut (32 )
8988 .stride (1 , 1 )
9089 .padding (2 , 2 )
@@ -95,7 +94,7 @@ private ConvolutionLayer conv3x3Stride1Padding2() {
9594
9695 private SubsamplingLayer pooling2x2Stride1 () {
9796 return new SubsamplingLayer .Builder (SubsamplingLayer .PoolingType .MAX )
98- .kernelSize (2 ,2 )
97+ .kernelSize (2 , 2 )
9998 .stride (1 , 1 )
10099 .build ();
101100 }
0 commit comments