Skip to content

Commit

Permalink
change timestamp type from long to string for 32-bit ARM architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeslabreche committed Mar 25, 2021
1 parent 540d8b7 commit 9bd3ffa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
10 changes: 5 additions & 5 deletions Mochi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ train 0 0.11 0.22 0.33 0.44 0.55 0.43 1615255010842
1. Start the Online ML server: `./OrbitAI_Mochi`
2. Send telnet commands to the server:
```
eval 'input="test_data/camera_tiny.txt"; echo "reset"; while IFS= read -r line; do sleep 0.02; echo "train ${line/+/''} $(date +%s%3N)"; done < "$input";' | telnet localhost 9999
eval 'input="test_data/camera_tiny.txt"; echo "reset"; while IFS= read -r line; do sleep 0.02; echo "train ${line/+/''} $(date +%s000)"; done < "$input";' | telnet localhost 9999
```
3. Monitor a model file being updated: `watch -n 0.1 cat models/arow_2D`

Expand All @@ -103,15 +103,15 @@ eval 'input="test_data/camera_tiny.txt"; echo "reset"; while IFS= read -r line;
1. Start the Online ML server: `./OrbitAI_Mochi`
2. Send telnet commands to the server:
```
eval 'echo "load"; sleep 1; input="test_data/camera_tiny.txt"; while IFS= read -r line; do sleep 0.02; echo "infer ${line/+/''} $(date +%s%3N)"; done < "$input";' | telnet localhost 9999
eval 'echo "load"; sleep 1; input="test_data/camera_tiny.txt"; while IFS= read -r line; do sleep 0.02; echo "infer ${line/+/''} $(date +%s000)"; done < "$input";' | telnet localhost 9999
```

### Validation
As a pre-requisite, make sure that `src/OrbitAI_Mochi.cpp` is compiled with the `LOG_TIMES` define set to 0. This validation procedure is to check that the models save and load as expected. First, train and infer data without loading the the saved model files:
1. Start the Online ML server: `./OrbitAI_Mochi`
2. Delete any previously saved models and log files followed by training and infering test data:
```
eval 'echo "reset"; sleep 1; input="test_data/camera_train_and_infer_small.txt"; while IFS= read -r line; do sleep 0.02; echo "${line/+/''} $(date +%s%3N)"; done < "$input";' | telnet localhost 9999
eval 'echo "reset"; sleep 1; input="test_data/camera_train_and_infer_small.txt"; while IFS= read -r line; do sleep 0.02; echo "${line/+/''} $(date +%s000)"; done < "$input";' | telnet localhost 9999
```
3. Rename the `logs/training.csv` file to `logs/training1.csv` so the logged trianing data is not lost the next time that the `reset` command is invoked: `mv logs/training.csv logs/training1.csv`
4. Rename the `logs/inference.csv` file to `logs/inference1.csv` so the logged inference results are not lost the next time that the `reset` command is invoked: `mv logs/inference.csv logs/inference1.csv`
Expand All @@ -120,15 +120,15 @@ Retrain the models from scratch but this time skip the inference:
1. Start the Online ML server: `./OrbitAI_Mochi`
2. Train and save the models:
```
eval 'echo "reset"; sleep 1; input="test_data/camera_small.txt"; while IFS= read -r line; do sleep 0.02; echo "train ${line/+/''} $(date +%s%3N)"; done < "$input";' | telnet localhost 9999
eval 'echo "reset"; sleep 1; input="test_data/camera_small.txt"; while IFS= read -r line; do sleep 0.02; echo "train ${line/+/''} $(date +%s000)"; done < "$input";' | telnet localhost 9999
```
3. Diff `logs/training1.csv` and `logs/training.csv`. Both files should be exactly the same: `diff logs/training1.csv logs/training.csv`

Load the saved models and infer given validation inputs. The inference results will be compared against those obtained in step 3:
1. Start the Online ML server: `./OrbitAI_Mochi`
2. Load saved models and infer:
```
eval 'echo "load"; sleep 1; input="test_data/camera_validation_small.txt"; while IFS= read -r line; do sleep 0.02; echo "infer ${line/+/''} $(date +%s%3N)"; done < "$input";' | telnet localhost 9999
eval 'echo "load"; sleep 1; input="test_data/camera_validation_small.txt"; while IFS= read -r line; do sleep 0.02; echo "infer ${line/+/''} $(date +%s000)"; done < "$input";' | telnet localhost 9999
```
3. Diff `logs/inference1.csv` and `logs/inference.csv`. Both files should be exactly the same: `diff logs/inference1.csv logs/inference.csv`

Expand Down
16 changes: 10 additions & 6 deletions Mochi/src/OrbitAI_Mochi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ int main(int argc, char *argv[])
{
/**
* Expected command string format:
* train <label:int> <pd1:float> <pd2:float> <pd3:float> <pd4:float> <pd5:float> <pd6:float> <timestamp:long>
* train <label:int> <pd1:float> <pd2:float> <pd3:float> <pd4:float> <pd5:float> <pd6:float> <timestamp:string>
*
* e.g.:
* train 1 0.11 0.22 0.33 0.44 0.55 1.23 1615253200322
Expand Down Expand Up @@ -611,7 +611,9 @@ int main(int argc, char *argv[])
float pd6 = std::stof(cmdTokens[7]);

// PD acquisition timestamp.
long timestamp = std::stol(cmdTokens[8]);
// A long in SEPP's ARM architecture is 32 bit so it can't fit the timestamp in ms.
// Use a string instead (we only use this value for logging).
std::string timestamp = cmdTokens[8];

// Training input error.
if(!(label == 0 || label == -1 || label == 1))
Expand Down Expand Up @@ -953,7 +955,7 @@ int main(int argc, char *argv[])
// Creating the training row string to append to the log file.
std::string trainingLogFileRow =
#if LOG_TIMES
std::to_string(timestamp) + "," +
timestamp + "," +
#endif
std::to_string(pd1) + "," + std::to_string(pd2) + "," + std::to_string(pd3) + "," + std::to_string(pd4) + "," + std::to_string(pd5) + "," + std::to_string(pd6) + "," + std::to_string(label)
#if LOG_TIMES
Expand Down Expand Up @@ -995,7 +997,7 @@ int main(int argc, char *argv[])
{
/**
* Expected command string format:
* infer <expected_label:int> <pd1:float> <pd2:float> <pd3:float> <pd4:float> <pd5:float> <pd6:float> <timestamp:long>
* infer <expected_label:int> <pd1:float> <pd2:float> <pd3:float> <pd4:float> <pd5:float> <pd6:float> <timestamp:string>
*
* e.g.:
* infer +1 0.11 0.22 0.33 0.44 0.55 1.23 1615253200322
Expand Down Expand Up @@ -1025,7 +1027,9 @@ int main(int argc, char *argv[])
float pd6 = std::stof(cmdTokens[7]);

// PD acquisition timestamp.
long timestamp = std::stol(cmdTokens[8]);
// A long in SEPP's ARM architecture is 32 bit so it can't fit the timestamp in ms.
// Use a string instead (we only use this value for logging).
std::string timestamp = cmdTokens[8];

// inference input error.
if(!(label == 0 || label == -1 || label == 1))
Expand Down Expand Up @@ -1280,7 +1284,7 @@ int main(int argc, char *argv[])
// Creating the inference results row string to append to the log file.
std::string inferenceLogFileRow =
#if LOG_TIMES
std::to_string(timestamp) + "," +
timestamp + "," +
#endif
std::to_string(pd1) + "," + std::to_string(pd2) + "," + std::to_string(pd3) + "," + std::to_string(pd4) + "," + std::to_string(pd5) + "," + std::to_string(pd6) + "," + std::to_string(label) + ","
+ predictions
Expand Down

0 comments on commit 9bd3ffa

Please sign in to comment.