mikeyEcology / MLWIC

Machine Learning for Wildlife Image Classification
70 stars 16 forks source link

I am not an R user and am unable to run devtools::install_github("mikeyEcology/MLWIC") command.Kindly guide me please #37

Open kaditi14 opened 4 years ago

mikeyEcology commented 4 years ago

Can you please provide the code that R output when you ran the command? If you are running on a Windows computer, you will likely need to have Rtools installed. This is easily installed following that link.

kaditi14 commented 4 years ago

Hey, thanks for replying so quick. Actually I got the solution to that problem.I am operating on ubuntu 16.04 on r studio ide version(1.2.5033).I tried running the setup.R function, but it gave me an error. I'm attaching a screen shot.

On Fri, Apr 10, 2020 at 3:09 PM mikey_t notifications@github.com wrote:

Can you please provide the code that R output when you ran the command? If you are running on a Windows computer, you will likely need to have Rtools installed https://cran.r-project.org/bin/windows/Rtools/. This is easily installed following that link.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mikeyEcology/MLWIC/issues/37#issuecomment-611960663, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJZMZ3OUUOHOMU2I7MPJAZLRL3SNFANCNFSM4MFIFXLQ .

mikeyEcology commented 4 years ago

I'm unable to see the screenshot. Can you copy and paste from your console? Also, we have a new out, MLWIC2 that I'd recommend using if you're just starting out.

kaditi14 commented 4 years ago

reticulate::conda_install("r-reticulate", packs) Error: Unable to find conda binary. Is Anaconda installed?

Is the error message displayed. Do I need to install anaconda for buntu as well.

On Fri, Apr 10, 2020 at 3:29 PM mikey_t notifications@github.com wrote:

I'm unable to see the screenshot. Can you copy and paste from your console? Also, we have a new out, MLWIC2 https://github.com/mikeyEcology/MLWIC2 that I'd recommend using if you're just starting out.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mikeyEcology/MLWIC/issues/37#issuecomment-611966885, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJZMZ3KYKFP5G3SIBSCQRITRL3UZPANCNFSM4MFIFXLQ .

mikeyEcology commented 4 years ago

Yes-you need to have Anaconda installed to run this software. Also, if you don't have much experience in R, I'd recommend instead using MLWIC2. MLWIC2 allows you to run these functions using a point-and-click GUI.

kaditi14 commented 4 years ago

Hey, I did that but my setup gives this error.

- create a conda environment if it doesn't already exist

if(!r_reticulate){

  • first remove conda environment

  • reticulate::conda_remove("r-reticulate")
  • then create it

  • reticulate::conda_create("r-reticulate", conda=conda_loc)
  • } Error: object 'r_reticulate' not found

On Fri, Apr 10, 2020 at 7:57 PM mikey_t notifications@github.com wrote:

Yes-you need to have Anaconda installed to run this software. Also, if you don't have much experience in R, I'd recommend instead using MLWIC2 https://github.com/mikeyEcology/MLWIC2. MLWIC2 allows you to run these functions using a point-and-click GUI.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mikeyEcology/MLWIC/issues/37#issuecomment-612052421, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJZMZ3NFDKPQF2BBI7YFDTLRL4UDXANCNFSM4MFIFXLQ .

kaditi14 commented 4 years ago

Also, classify.R and make_output.R were executed, but the result files were not visible at the specified location.

' @param architecture the architecture of the deep neural network

(DNN). Resnet-18 is the default.

' Options are c("alexnet", "densenet", "googlenet", "nin", "resnet",

"vgg").

' If you are using the trained model that comes with MLWIC, use resnet

18 (the default).

' If you trained a model using a different architechture, you need to

specify this same architechture and depth

' that you used for training.

' @param depth the number of layers in the DNN. If you are using the

built in model, do not adjust this parameter.

' If you are using a model that you trained, use the same architecture

and depth as that model.

' @param model_dir Absolute path to the location where you stored the L1

folder

' that you downloaded from github.

' @export

classify <- function(

  • path_prefix ="/home/aditi/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a/alldata/images",

    absolute path to location of the images on your computer

  • data_info = "/home/aditi/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a/alldata/image_labels.csv",

    csv with file names for each photo. See details

  • model_dir = "/home/aditi/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a",
  • save_predictions = "model_predictions.txt", # txt file where you want model output to go
  • python_loc = "/usr/bin/python", # location of the python that Anacnoda uses on your machine
  • num_classes = 28, # number of classes in model
  • delimiter = ",", # this will be , for a csv.
  • architecture = "resnet",
  • depth = "18",
  • log_dir = "USDA182"
  • ){
  • wd1 <- getwd() # the starting working directory
  • set these parameters before changing directory

  • path_prefix = path_prefix
  • data_info = data_info
  • model_dir = model_dir
  • navigate to directory with trained model

  • if(endsWith(model_dir, "/")){
  • setwd(paste0(model_dir, "L1"))
  • } else {
  • setwd(paste0(model_dir, "/L1"))
  • }
  • wd <- getwd()
  • load in data_info and store it in the model_dir

  • lbls <- utils::read.csv(data_info, header=FALSE)

  • lbls[,1] <- as.character(lbls[,1])

  • utils::write.table(lbls, "data_info.csv", sep=",",

  • row.names=FALSE, col.names=FALSE)

  • file.copy(from=data_info, to=paste0(wd, "/data_info.csv"),

    header=FALSE)

  • cpfile <- paste0("cp ", data_info, " ", wd, "/data_info.csv")
  • system(cpfile)
  • set depth

  • if(architecture == "alexnet"){
  • depth <- 8
  • }
  • if(architecture == "nin"){
  • depth <- 16
  • }
  • if(architecture == "vgg"){
  • depth <- 22
  • }
  • if(architecture == "googlenet"){
  • depth <- 32
  • }
  • set up code

  • eval_py <- paste0(python_loc,
  • "python eval.py --architecture ", architecture,
  • " --depth ", depth,
  • " --log_dir ", log_dir,
  • " --path_prefix ", path_prefix,
  • " --batch_size 128 --data_info data_info.csv",
  • " --delimiter ", delimiter,
  • " --save_predictions ", save_predictions,
  • " --num_classes=", num_classes, "\n")
  • run code

  • toc <- Sys.time()
  • system(eval_py)
  • tic <- Sys.time()
  • runtime <- difftime(tic, toc, units="auto")
  • end function

  • txt <- paste0("evaluation of images took ", runtime, " ", units(runtime), ". ",
  • "The results are stored in ", model_dir, "/L1/", save_predictions, ". ",
  • "To view the results in a viewer-friendly format, please use the function make_output")
  • print(txt)
  • return to previous working directory

  • setwd(wd1)
  • } setwd("~/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a/alldata")

' @param architecture the architecture of the deep neural network

(DNN). Resnet-18 is the default.

' Options are c("alexnet", "densenet", "googlenet", "nin", "resnet",

"vgg").

' If you are using the trained model that comes with MLWIC, use resnet

18 (the default).

' If you trained a model using a different architechture, you need to

specify this same architechture and depth

' that you used for training.

' @param depth the number of layers in the DNN. If you are using the

built in model, do not adjust this parameter.

' If you are using a model that you trained, use the same architecture

and depth as that model.

' @param model_dir Absolute path to the location where you stored the L1

folder

' that you downloaded from github.

' @export

classify <- function(

  • path_prefix ="/home/aditi/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a/alldata/images",

    absolute path to location of the images on your computer

  • data_info = "/home/aditi/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a/alldata/image_labels.csv",

    csv with file names for each photo. See details

  • model_dir = "/home/aditi/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a/alldata",
  • save_predictions = "model_predictions.txt", # txt file where you want model output to go
  • python_loc = "/usr/bin/python", # location of the python that Anacnoda uses on your machine
  • num_classes = 28, # number of classes in model
  • delimiter = ",", # this will be , for a csv.
  • architecture = "resnet",
  • depth = "18",
  • log_dir = "USDA182"
  • ){
  • wd1 <- getwd() # the starting working directory
  • set these parameters before changing directory

  • path_prefix = path_prefix
  • data_info = data_info
  • model_dir = model_dir
  • navigate to directory with trained model

  • if(endsWith(model_dir, "/")){
  • setwd(paste0(model_dir, "L1"))
  • } else {
  • setwd(paste0(model_dir, "/L1"))
  • }
  • wd <- getwd()
  • load in data_info and store it in the model_dir

  • lbls <- utils::read.csv(data_info, header=FALSE)

  • lbls[,1] <- as.character(lbls[,1])

  • utils::write.table(lbls, "data_info.csv", sep=",",

  • row.names=FALSE, col.names=FALSE)

  • file.copy(from=data_info, to=paste0(wd, "/data_info.csv"),

    header=FALSE)

  • cpfile <- paste0("cp ", data_info, " ", wd, "/data_info.csv")
  • system(cpfile)
  • set depth

  • if(architecture == "alexnet"){
  • depth <- 8
  • }
  • if(architecture == "nin"){
  • depth <- 16
  • }
  • if(architecture == "vgg"){
  • depth <- 22
  • }
  • if(architecture == "googlenet"){
  • depth <- 32
  • }
  • set up code

  • eval_py <- paste0(python_loc,
  • "python eval.py --architecture ", architecture,
  • " --depth ", depth,
  • " --log_dir ", log_dir,
  • " --path_prefix ", path_prefix,
  • " --batch_size 128 --data_info data_info.csv",
  • " --delimiter ", delimiter,
  • " --save_predictions ", save_predictions,
  • " --num_classes=", num_classes, "\n")
  • run code

  • toc <- Sys.time()
  • system(eval_py)
  • tic <- Sys.time()
  • runtime <- difftime(tic, toc, units="auto")
  • end function

  • txt <- paste0("evaluation of images took ", runtime, " ", units(runtime), ". ",
  • "The results are stored in ", model_dir, "/L1/", save_predictions, ". ",
  • "To view the results in a viewer-friendly format, please use the function make_output")
  • print(txt)
  • return to previous working directory

  • setwd(wd1)
  • } setwd("~/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a/alldata")

    ' set your working directory to the location where you stored your

    images folder and data_info csv.

    '

    ' @param output_location Absolute path where you want the output csv

    stored. This path

    ' must exist on your computer.

    ' @param output_name Desired name of the output file

    ' @param saved_predictions This is the file name where you stored

    predictions when you ran

    ' \code{classify}. If you used the default in that function, you can

    use the default here.

    ' @param model_dir Absolute path to the location where you stored the L1

    folder

    ' that you downloaded from github.

    ' @export

    make_output <- function(

  • output_location="/home/aditi/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a",

  • model_dir="/home/aditi/Desktop/PROJECT_FILES/mikeyEcology-MLWIC-14b364a",

  • output_name = "output.csv",
  • saved_predictions = "model_predictions.txt"
  • ){
  • wd1 <- getwd() # the starting working directory
  • set these parameters before changing directory

  • output_location = output_location
  • model_dir = model_dir
  • - read in text file of model output

  • navigate to directory with trained model

  • if(endsWith(model_dir, "/")){
  • setwd(paste0(model_dir, "L1"))
  • } else {
  • setwd(paste0(model_dir, "/L1"))
  • }
  • out <- utils::read.csv(saved_predictions, header=FALSE)
  • set new column names

  • colnames(out) <- c("rowNumber", "fileName", "answer", "guess1", "guess2", "guess3", "guess4", "guess5",
  • "confidence1", "confidence2", "confidence3", "confidence4", "confidence5")
  • get rid of [ ]

  • out$guess1 <- gsub("[", "", out$guess1, fixed=TRUE)
  • out$confidence1 <- gsub("[", "", out$confidence1, fixed=TRUE)
  • out$guess5 <- gsub("]", "", out$guess5, fixed=TRUE)
  • out$confidence5 <- gsub("]", "", out$confidence5, fixed=TRUE)
  • output

  • if(endsWith(output_location, "/")){
  • output_full <- paste0(output_location, output_name)
  • } else {
  • output_full <- paste0(output_location, "/", output_name)
  • }
  • utils::write.csv(out[,-1], output_full)
  • print(paste0("Output can be found here: ", output_full))
  • return to previous working directory

  • setwd(wd1)
  • }

On Fri, Apr 10, 2020 at 11:23 PM aditi kukde aditikukde123@gmail.com wrote:

Hey, I did that but my setup gives this error.

- create a conda environment if it doesn't already exist

if(!r_reticulate){

  • first remove conda environment

  • reticulate::conda_remove("r-reticulate")
  • then create it

  • reticulate::conda_create("r-reticulate", conda=conda_loc)
  • } Error: object 'r_reticulate' not found

On Fri, Apr 10, 2020 at 7:57 PM mikey_t notifications@github.com wrote:

Yes-you need to have Anaconda installed to run this software. Also, if you don't have much experience in R, I'd recommend instead using MLWIC2 https://github.com/mikeyEcology/MLWIC2. MLWIC2 allows you to run these functions using a point-and-click GUI.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/mikeyEcology/MLWIC/issues/37#issuecomment-612052421, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJZMZ3NFDKPQF2BBI7YFDTLRL4UDXANCNFSM4MFIFXLQ .