R/createAlexNetModel.R
createAlexNetModel2D.Rd
Creates a keras model of the AlexNet deep learning architecture for image recognition based on the paper
createAlexNetModel2D( inputImageSize, numberOfClassificationLabels = 1000, numberOfDenseUnits = 4096, dropoutRate = 0, mode = c("classification", "regression"), batch_size = NULL )
inputImageSize | Used for specifying the input tensor shape. The shape (or dimension) of that tensor is the image dimensions followed by the number of channels (e.g., red, green, and blue). The batch size (i.e., number of training images) is not specified a priori. |
---|---|
numberOfClassificationLabels | Number of segmentation labels. |
numberOfDenseUnits | number of dense units. |
dropoutRate | optional regularization parameter between |
mode | 'classification' or 'regression'. |
batch_size | batch size to pass to first layer |
an AlexNet keras model
A. Krizhevsky, and I. Sutskever, and G. Hinton. ImageNet Classification with Deep Convolutional Neural Networks.
available here:
http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks.pdf
This particular implementation was influenced by the following python implementation:
https://github.com/duggalrahul/AlexNet-Experiments-Keras/ https://github.com/lunardog/convnets-keras/
Tustison NJ
#> Error in py_discover_config(required_module, use_environment): Python specified in RETICULATE_PYTHON (/Users/ntustison/anaconda3/envs/antsx/bin/python3) does not existnumberOfLabels <- 10 # Extract a small subset for something that can run quickly X_trainSmall <- mnistData$train$x[1:10,,]#> Error in eval(expr, envir, enclos): object 'mnistData' not found#> Error in array(data = X_trainSmall, dim = c(dim(X_trainSmall), 1)): object 'X_trainSmall' not found#> Error in to_categorical(mnistData$train$y[1:10], numberOfLabels): object 'mnistData' not foundX_testSmall <- mnistData$test$x[1:10,,]#> Error in eval(expr, envir, enclos): object 'mnistData' not found#> Error in array(data = X_testSmall, dim = c(dim(X_testSmall), 1)): object 'X_testSmall' not found#> Error in to_categorical(mnistData$test$y[1:10], numberOfLabels): object 'mnistData' not found# We add a dimension of 1 to specify the channel size inputImageSize <- c( dim( X_trainSmall )[2:3], 1 )#> Error in eval(expr, envir, enclos): object 'X_trainSmall' not foundmodel <- createAlexNetModel2D( inputImageSize = inputImageSize, numberOfClassificationLabels = numberOfLabels )#> Error in py_discover_config(required_module, use_environment): Python specified in RETICULATE_PYTHON (/Users/ntustison/anaconda3/envs/antsx/bin/python3) does not existmodel %>% compile( loss = 'categorical_crossentropy', optimizer = optimizer_adam( lr = 0.0001 ), metrics = c( 'categorical_crossentropy', 'accuracy' ) )#> Error in compile(., loss = "categorical_crossentropy", optimizer = optimizer_adam(lr = 1e-04), metrics = c("categorical_crossentropy", "accuracy")): object 'model' not found#> used (Mb) gc trigger (Mb) limit (Mb) max used (Mb) #> Ncells 2499616 133.5 4570014 244.1 NA 4570014 244.1 #> Vcells 4401972 33.6 10146329 77.5 65536 6648755 50.8#> Warning: object 'mnistData' not found#> used (Mb) gc trigger (Mb) limit (Mb) max used (Mb) #> Ncells 2498889 133.5 4570014 244.1 NA 4570014 244.1 #> Vcells 4400774 33.6 10146329 77.5 65536 6648755 50.8# Comment out the rest due to travis build constraints # track <- model %>% fit( X_trainSmall, Y_trainSmall, verbose = 1, # epochs = 1, batch_size = 2, shuffle = TRUE, validation_split = 0.5 ) # Now test the model # testingMetrics <- model %>% evaluate( X_testSmall, Y_testSmall ) # predictedData <- model %>% predict( X_testSmall, verbose = 1 ) rm(model); gc()#> Warning: object 'model' not found#> used (Mb) gc trigger (Mb) limit (Mb) max used (Mb) #> Ncells 2498956 133.5 4570014 244.1 NA 4570014 244.1 #> Vcells 4400848 33.6 10146329 77.5 65536 6648755 50.8