MLWIC: Machine Learning for Wildlife Image Classification in R Issues with Python

machine learning to classify animal species in camera trap images
animal classification machine learning
github camera trap

I am a wildlife PhD researcher manually identifying ~1.5 million game camera photos by species. A machine learning package in R has recently come out of a research project and I've been trying to get the script to run in R for about 12 hours and can't seem to get it right (I have used R and python a lot, but I am no expert and this is the first question I have asked on here so forgive me if I haven't done this correctly).

The ReadMe (To understand what I am trying to do you will probably have to read this, I apologize) for the package downloaded on Github is located at: https://github.com/mikeyEcology/MLWIC/blob/master/README.md

Unfortunately for me, the package was developed on a Macintosh platform and I have Windows. I followed the steps in the ReadMe as follows:

1: Installed the MLWIC package using the code:

devtools::install_github("mikeyEcology/MLWIC")
library(MLWIC)

2: Followed the instructions to install "pip", python, and "TensorFlow" at https://www.tensorflow.org/install/pip

3: Downloaded the L1 folder

4: I ran a different code than outlined in the ReadMe, it is as follows: setup(python_loc = "I used this location I got from running "where python" in Anaconda")

After this initial setup, I ran the code for the "classify function": library(MLWIC)

setup(python_loc = "C:/ProgramData/Anaconda3", conda_loc = "auto", r_reticulate = FALSE)

setwd("C:/Users/werdel/Desktop/MachineLearning")

help("classify")

classify(path_prefix = "C:/Users/werdel/Desktop/MachineLearning/images",# this is the absolute path to the images. 

     data_info = "C:/Users/werdel/Desktop/MachineLearning/image_labels.csv", # this is the location of the csv containing image information. It has Unix linebreaks and no headers.

     model_dir = "C:/Users/werdel/Desktop/MachineLearning", # assuming this is where you stored the L1 folder in Step 3 of the instructions: github.com/mikeyEcology/MLWIC/blob/master/README

     python_loc = "C:/ProgramData/Anaconda3/python.exe", # the location of Python on your computer. 

     save_predictions = "model_predictions.txt" # this is the default and you should use it unless you have reason otherwise.)

This is where the problem seemed to arise. It seems to run fine, with the output showing a file created in my working directory, but when I check, there is no file. I have tried changing python location, downloading new and old versions of anaconda, messing with environments, but nothing has changed the fact that there is no file created in my working directory:

> library(MLWIC)
> setup(python_loc = "C:/ProgramData/Anaconda3", conda_loc = "auto", r_reticulate = FALSE)

Remove all packages in environment C:\PROGRA~3\ANACON~1\envs\r-reticulate:


## Package Plan ##

  environment location: C:\PROGRA~3\ANACON~1\envs\r-reticulate


The following packages will be REMOVED:

ca-certificates: 2018.03.07-0          
certifi:         2018.10.15-py37_0     
openssl:         1.1.1a-he774522_0     
pip:             18.1-py37_0           
python:          3.7.1-he44a216_5      
setuptools:      40.6.2-py37_0         
vc:              14.1-h0510ff6_4       
vs2015_runtime:  14.15.26706-h3a45250_0
wheel:           0.32.3-py37_0         
wincertstore:    0.2-py37_0            

Solving environment: ...working... done

## Package Plan ##

  environment location: C:\PROGRA~3\ANACON~1\envs\r-reticulate

  added / updated specs: 
    - python


The following NEW packages will be INSTALLED:

ca-certificates: 2018.03.07-0          
certifi:         2018.10.15-py37_0     
openssl:         1.1.1a-he774522_0     
pip:             18.1-py37_0           
python:          3.7.1-he44a216_5      
setuptools:      40.6.2-py37_0         
vc:              14.1-h0510ff6_4       
vs2015_runtime:  14.15.26706-h3a45250_0
wheel:           0.32.3-py37_0         
wincertstore:    0.2-py37_0            

Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
#
# To activate this environment, use:
# > activate r-reticulate
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#

Solving environment: ...working... failed

UnsatisfiableError: The following specifications were found to be in conflict:
  - argparse
  - tensorflow
Use "conda info <package>" to see the dependencies for each package.

Error: Error 1 occurred installing packages into conda environment r-reticulate
> classify(path_prefix = "C:/Users/werdel/Desktop/MachineLearning/images", # this is 
the absolute path to the images. 
+          data_info = "C:/Users/werdel/Desktop/MachineLearning/image_labels.csv", # 
this is the location of the csv containing image information. It has Unix linebreaks 
and no headers.
+          model_dir = "C:/Users/werdel/Desktop/MachineLearning", # assuming this is 
where you stored the L1 folder in Step 3 of the instructions: 
github.com/mikeyEcology/MLWIC/blob/master/README
+          python_loc = "C:/ProgramData/Anaconda3/python.exe", # the location of Python 
on your computer. 
+          save_predictions = "model_predictions.txt" # this is the default and you 
should use it unless you have reason otherwise.
+ )
[1] "evaluation of images took 0.000504970550537109 secs. The results are stored in 
C:/Users/werdel/Desktop/MachineLearning/L1/model_predictions.txt. To view the results 
in a viewer-friendly format, please use the function make_output"

So my final question is, does it seem like I set something up wrong while downloading pip, tensorflow, anaconda, and python, is it something with the way I am coding, etc.?

If I am not mistaken there is a small bug in their code that ignores the "data_info" path. Try renaming your "image_labels.csv" to "data_info.csv" and put the file inside the model_dir. This solved the problem for me. Also, use "C:/ProgramData/Anaconda3/" instead of "C:/ProgramData/Anaconda3/python.exe"

MLWIC: Machine Learning for Wildlife Image Classification in R , 0 which includes python 3.6.5. After many hours of troubleshooting I got it to work. Once Anaconda is installed I used Anaconda Navigator to  MLWIC: Machine Learning for Wildlife Image Classification in R This package identifies animal species in camera trap images by implementing the model described in Tabak et al. . I am currently developing MLWIC2 , which has some added functionality (including Shiny apps) and a newly-trained model with 58 species, but is still in the development

I was able to get MLWIC to run relatively pain-free on Mac. Getting it running on windows was a little more frustrating. I followed issue threads #6 and #13 on the MLWIC github page. On a machine running Windows 10 I downloaded Anaconda 3 5.2.0 which includes python 3.6.5. After many hours of troubleshooting I got it to work.

Once Anaconda is installed I used Anaconda Navigator to install tensorflow 1.11.0, cuddn 6.0, setuptools 40.6.2. Note this is the only place that I installed tensorflow. I did not bother with the pip install as mentioned on the tensorflow web page.

From there when first opening R I installed the following packages MLWIC, keras, cloudml, Rcpp, and reticulate. Then ran them with the library function. Also as Faisal Ahmed stated above rename image_labels.csv to data_info.csv, and move that file to the L1 folder. From here I was able to get the MLWIC provided code to run on windows. When I first ran the setup function it looked like this setup(python_loc = "C:/Users/kvanatta/Anaconda3/python")

Note: I was originally trying to get MLWIC to run with the files saved on the server in my office (S: drive) and could not get it to work. Upon transferring the files to a 1tb external hard drive (F: drive) everything worked fine from the new location.

I also downloaded the program notepad ++ to be able to convert the data_info.csv file to unix(lf) linebreaks. I believe since windows does not use these linebreaks, opening the .csv file in excel will change the line breaks. You can use notepad ++ to change them back.

Hope this helps ease some frustrations.

Cheers

mikeyEcology/MLWIC: README.md, MLWIC: Machine Learning for Wildlife Image Classification in R MLWIC will run on Python 3.6 and on Windows computers, but running on Windows will If you are having trouble running MLWIC on Windows, you can see this companion  Machine Learning for Wildlife Image Classification (MLWIC) is an R package that allows users to automatically classify animal species in camera trap images.

I really struggled to get MLWIC working on my Windows computer and followed a number of the issues on the MLWIC github page until I came up with a solution that worked for me.

I wrote up a guide for windows users and it's been added to the MLWIC_examples repo. You can find it here. It is a step-by-step guide.

As as aside, I found a way to use Unix-type linebreaks without leaving the R environment:

# Write to UNIX type doc (required)
output.file <- file("L1\\data_info.csv", "wb")
write.table(data_info,
            row.names = FALSE,
            col.names = FALSE,
            file = output.file,
            quote = FALSE,
            append = TRUE,
            sep = ",")
close(output.file)
rm(output.file) 

python: MLWIC: Machine Learning for Wildlife Image Classification , I am a wildlife PhD researcher manually identifying ~1.5 million game camera photos by species. A machine learning package in R has  MLWIC2: Machine Learning for Wildlife Image Classification. MLWIC2 is similar to the MLWIC package, it contains two models: the species_model identifies 58 species and empty images, and the empty_animal model distinguishes between images with animals and those that are empty. MLWIC2 also contains Shiny apps for running the functions.

[PDF] ClassifyMe: a field-scouting software for the identification of wildlife , and resolves privacy issues surrounding transfer and third-party access to limitations and considerations when designing machine learning The most relevant alternative is the MLWIC: Machine Learning for Wildlife Image. Classification in R package (Tabak et al. (Python) and hardware configuration. mikeyEcology/MLWIC: Machine Learning for Wildlife Image Classification This package evaluates images using the Species Level model from Tabak et al. in the function MLWIC_eval. It also allows users to train their own machine learning model to classify wildlife using the MLWIC_train.

mikeyEcology ( mikey_t ), 0. mikeyEcology/MLWIC 47. Machine Learning for Wildlife Image Classification Classify camera trap images using machine learning with R Shiny Apps It seems the only way I can run my python code in the terminal is to copy from my script If anyone else is having this problem try running the make_input function with  Tabak, M. A., M. S. Norouzzadeh, D. W. Wolfson, S. J. Sweeney, K. C. VerCauteren, N. P. Snow, J. M. Halseth, P. A. D. Salvo, J. S. Lewis, M. D. White, B. Teton, J. C. Beasley, P. E. Schlichting, R. K. Boughton, B. Wight, E. S. Newkirk, J. S. Ivan, E. A. Odell, R. K. Brook, P. M. Lukacs, A. K. Moeller, E. G. Mandeville, J. Clune, and R. S. Miller.

ClassifyMe: A Field-Scouting Software for the Identification of , A key problem in the wildlife ecology field is that vast amounts of time is spent is the MLWIC: Machine Learning for Wildlife Image Classification in R package [​53]. Within R, there are Python binding libraries which also allow access to  MLWIC_examples: Using the MLWIC or MLWIC2 (Machine Learning for Wildlife Image Classification) R Package If you are using MLWIC2, simply download (or clone) this repository to your local machine and follow the instructions in the readme.

Comments
  • did you ever figure this out? I am hoping to use this software in a few months, from a windows machine.
  • Hey Faisal! Thanks for taking an interest in our issue. I tried your suggestion (my Anaconda install is in C:/Anaconda3) but no dice. Any other suggestions?