Depth video data-enabled predictions of longitudinal dairy cow body weight using thresholding and Mask R-CNN algorithms
This repo contains all the code used in Bi et al.(2023).
This repository includes:
- Quick sample code.
- Thresholding methods
- 2.1 Single threshold method.
- 2.2 Adaptive threshold method.
- Mask RCNN method
- 3.1 LabelMe.
- 3.2 Mask-RCNN method
- 3.2.1 Training Mask-RCNN model
- 3.2.2 Predict depth images by trained Mask-RCNN model.
- Build Body Weight Regression Model
- 4.1 Data Preprocessing
- 4.2 Goodness of fit
- 4.3 Cross-Validation 1
- 4.4 Cross-Validation 2
Attention: This sample code works with example images. For your customized images, some hyperparameters need to be adjusted.
- Download python folder from this github into your local postion.
- Install all the packages you will use in requirement.txt. Recreate one conda environment follow the lines.
# $ conda create --name <env> --file <requirement.txt>
- Build one empty folder named
outputs
within your local folderpython
which you downloaded from this github repository. - If you want to run for your own figures, please make sure your files following our
Sample_files
folder structure.
- Please make sure the
outputs
folder is empty before running each image analysis method.
Select one image analysis method below and run the related code block
- Single threshold method:
python single_thr/ImageAnalysis_single_thr.py D1
- Adaptive threshold method:
python adaptive_thr/ImageAnalysis_adaptive_thr.py D1
- Mask R-CNN method:
python maskrcnn/ImageAnalysis_mrcnn.py D1
After running, each approach will generate one csv file in outputs/D1
folder similar to the following.
- The code was forked from https://github.com/uf-aiaos/ShinyAnimalCV
- How to install LabelMe
- How to use LabelMe to label image
## How to used our customized LabelMe.
## Code used to start label png into json files.
labelme ./depth/cow.png -O ./outputs/cow.json
# Code used to transfer json files into folders.
labelme_json_to_dataset ./outputs/cow.json -o ./outputs/cow_json
- The code was forked from https://github.com/uf-aiaos/ShinyAnimalCV
- .ipynb file
- .h5 file