Skip to content

Depth video data-enabled predictions of longitudinal dairy cow body weight using thresholding and Mask R-CNN algorithms

Notifications You must be signed in to change notification settings

yebigithub/BW_dairy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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:

  1. Quick sample code.
  2. Thresholding methods
    • 2.1 Single threshold method.
    • 2.2 Adaptive threshold method.
  3. 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.
  4. Build Body Weight Regression Model
    • 4.1 Data Preprocessing
    • 4.2 Goodness of fit
    • 4.3 Cross-Validation 1
    • 4.4 Cross-Validation 2

1. Quick sample code.

Attention: This sample code works with example images. For your customized images, some hyperparameters need to be adjusted.

1.1 Establish your environment.

# $ conda create --name <env> --file <requirement.txt>

1.2 Run image analysis.

Step1. Create outputs directory.

  • Build one empty folder named outputs within your local folder python 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.

Step2. Choose one 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

Step3. Check your outputs.

After running, each approach will generate one csv file in outputs/D1folder similar to the following.

2. Thresholding methods

2.1 Single threshold method.

2.2 Adaptive threshold method.

Main steps

animated

3. Mask RCNN method

3.1 LabelMe.

## How to used our customized LabelMe.
## Code used to start label png into json files.
labelme ./depth/cow.png -O ./outputs/cow.json

animated

# Code used to transfer json files into folders.
labelme_json_to_dataset ./outputs/cow.json -o ./outputs/cow_json

3.2 Mask-RCNN method

3.2.1 Training Mask-RCNN model

3.2.2 Predict depth images by trained Mask-RCNN model.

4. Build Body Weight Regression Model

4.1 Data Preprocessing

4.2 Goodness of fit

4.3 Cross-Validation 1

4.4 Cross-Validation 2