# I. Behavior Monitoring Device
## 1.1 RPI-Settings
### 1.1.1 Account
```
Username: berlinpi
Password: ntubime405
```
### 1.1.2 WIFI
[WIFI-Setting](https://macdidi5.wordpress.com/2016/04/28/raspberry-pi%E5%A4%9A%E5%80%8Bwifi%E9%80%A3%E7%B7%9A%E8%A8%AD%E5%AE%9A/)
### 1.1.3 SSH
+ 透過牧場的router: 140.112.84.2
+ MobaXterm, VSCode, Filezilla 都可以連
```
Host berlinpi
HostName 140.112.84.2
User berlinpi
Port 222
```

## 1.2 RPI-Transmittance
### 1.2.1 SFTP (SSH File Transfer Protocol)
+ Filezilla
+ 
### 1.2.2 ImageZMQ (real-time image transmittance)
+ 要設定牧場router和實驗室電腦
+ [RPI-Publisher](https://drive.google.com/file/d/1SrKyTq4qUxn_F0T-7ysQ_NE-KumLi5mv/view?usp=drive_link)
+ [LabPC-Subscriber](https://drive.google.com/file/d/10wI9O2UChNtbg7I4geXUcd3WLenWcUnA/view?usp=drive_link)
## 1.3 RPI-Data-Collecting
+ [安排定時執行程式-cron](https://blog.gtwang.org/linux/linux-crontab-cron-job-tutorial-and-examples/)
+ [如果需要terminal不要斷-screen](https://blog.gtwang.org/linux/screen-command-examples-to-manage-linux-terminals/)
+ **cron settings, code for data collection應該都已經在RPI裡面**
+ [collecting-code](https://drive.google.com/file/d/1HnH2XRPXX7_9JAP8ZiMNTAh5j3uwXyxG/view?usp=drive_link)
+ 目前是 1 clip/min, 3.2 second, 10 FPS, 32 length
+ 1440 clips/day
+ 會自動存在某個資料夾 要定期傳回來 清出儲存空間
# II. Preprocessing
## 2.1 Data Preparation
+ **RPI --(SFTP)--> Computer --(SFTP)--> Toolmen Server**
+ 確認 1440 mp4s / day
+ Collected raw data: ```[2024xxxx] / 2024xxxx-00-00-03.mp4, 2024xxxx-00-01-03.mp4, ..., 2024xxxx-23-59-03.mp4```
+ Toolmen Server Destination: ```calf_data/Auto_Label/1_raw_daily_data/[2024xxxx]```
## 2.2 Video Data Preprocessing
+ crop / rotate / resize video data
+ preprocessing params 每隻牛不一樣
+ Input: ```calf_data/Auto_Label/1_raw_daily_data/[2024xxxx]```
+ Output: ```calf_data/Auto_Label/2_preprocessed_data/[2024xxxx]```
```
python3 calf_data/video_preprocess.py
```
## 2.3 Semi-automatic Annotation
+ 用一個 trained model 來幫我們先大致分好資料
+ 較不確定的樣本會被放在'Unknown'
+ Input: ```calf_data/Auto_Label/2_preprocessed_data/[2024xxxx]```
+ Output: ```calf_data/Auto_Label/3_auto_labeled/[2024xxxx]/AL,AS,DR,FD,NL,NS,RM,Unknown```
```
python3 main.py --root_path /home/ubuntu/CALF/V9/ --video_path calf_data/Dataset_V9/Dataset_V9/ --result_path result_train/ --model videomaev2 --official_hyper_params --resume_path optimized_models/V9_best/videomaev2_V9_b4_lr0.0005_ep80.pth --auto
```
# III. Labeling
## 3.1 Download Semi-Labeled Data
+ SFTP through Filezilla
+ Semi-labeled data path: ```calf_data/Auto_Label/3_auto_labeled/[2024xxxx]/AL,AS,DR,FD,NL,NS,RM,Unknown```
## 3.2 Manual Labeling
### 3.2.1 Definition

### 3.2.2 Start Labeling
**1. Go through `NL/` `AL/` `NS/` `AS/` `FD/` `DR/` `RM/` and check if correct**
- correct → pass
- not correct → move it to the correct folder
- not sure → move to `X/`
**2. View and classify data in `Unknown/`**
- can classify → move it to the correct folder
- not sure → move to `X/`
**3. Final check**
- All data in all folders have been viewed and classified
- No data in `Unknown/`
- The sum of data samples in all folders should be 1440
## 3.3 Upload to Toolmen Server
+ Manual labeled data path: ```calf_data/Auto_Label/4_manual/[2024xxxx]/AL,AS,DR,FD,NL,NS,RM,X```