Deep Learning CNN with R and Tensorflow

Data training is 1–20 sequence data of “Indomie” , and data from 31 until 50 images of “Sedap”train=gambar_resized[c(1:20,31:50)]test=gambar_resized[c(21:30,51:60)]par(mfrow=c(4,10))for (i in 1:40) plot(train[[i]])Data TrainingAnd do resized again for data training and testing, with height and width is 32 pixels.for (i in 1:40){train[[i]]=resize(train[[i]],32,32)}for (i in 1:20){test[[i]]=resize(test[[i]],32,32)}train=combine(train)x=tile(train,40)display(x,title("Train"))dim(train)test=combine(test)y=tile(test,20)display(y, title("Test"))dim(test)Change the arrangement of dimensions’ image and make label data categoricaltrain=aperm(train,c(4,1,2,3))test=aperm(test,c(4,1,2,3))dim(train)Begin the classification process and make label data categoricaltrainy=c(rep(0,20),rep(1,20))testy=c(rep(0,10),rep(1,10))trainLabels=to_categorical(trainy)testLabels=to_categorical(testy)Below is syntax to build the CNN modelmodel=keras_model_sequential()model%>% layer_conv_2d(filters=32, kernel_size = c(3,3), activation = "relu", input_shape = c(32,32,3))%>% #relu=rectivied linear unit..mengambil nilai tertinggi untuk aktivasi layer_conv_2d(filters = 32, kernel_size = c(3,3), activation = "relu")%>% layer_max_pooling_2d(pool_size = c(2,2))%>% layer_dropout(rate=0.01) %>% #untuk regularisasi pada node yang punya nilai kecil tidak akan diteruskan/dikerjakan layer_conv_2d(filters = 64, kernel_size = c(3,3), activation = "relu")%>% layer_max_pooling_2d(pool_size = c(2,2))%>% layer_dropout(rate=0.01) %>% layer_flatten()%>% #merubah menjadi vektor layer_dense(units=256, activation = "relu")%>% layer_dropout(rate=0.01) %>% layer_dense(units=3,activation = "softmax")%>% #unit=banyak objek yg akan di klasifikasi, softmax=hampir mirip dgn relu compile(loss="categorical_crossentropy", optimizer = optimizer_sgd(lr=0.01, decay = 1e-06, momentum = 0.9, nesterov=T), metrics=c('accuracy'))#sgd=stokastik gladiand descend (secara stokastik random memilih mana yg dengan cepat menuju global optimum) summary(model)Summary of ModelAccuracypred=model%>%predict_classes(test)predtable(predicted=pred, actual=testy)Accuracy— Good Luck! —“The way to get started is to quit talking and begin doing.” -Walt Disney-. More details

Leave a Reply