Skip to content

Commit

Permalink
[ADD] condition for writing .csv file
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCretois committed Sep 25, 2023
1 parent 805784b commit 8b29db7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,24 @@ cd snowmobile_analyzer
docker build -t snowmobile -f Dockerfile .
```

Run the program:
Run the program using the `analyze.sh` script which is a wrapper around the Docker command

```bash
./analyze.sh ./example/example_audio.mp3
```

Note that if you want to have more control over the arguments you can use Docker:

```bash
docker run \
--rm \
--gpus all \
-v ./logs:/app/logs \ # Important to write the log files
-v "$FOLDER_TO_EXPOSE":/data \
snowmobile \
--input /data/"$FILENAME"
```

Note that you can change `./example/example_audio.mp3` to the path of your own file.

### Use without Docker
Expand Down
22 changes: 15 additions & 7 deletions src/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def compute_hr(array):

return hr

def predict(testLoader, model, device, threshold=0.95):
def predict(testLoader, model, device, threshold=0.99):

proba_list = []
hr_list = []
Expand Down Expand Up @@ -112,13 +112,20 @@ def write_results(prob_audioclip_array, hr_array, outname, min_hr, min_conf):
# Update the start time of the detection
idx_begin = idx_end

with open(outname, "w") as file:
# Write only if there are some detections respecting our conditions
if len(rows_for_csv) > 0:
with open(outname, "w") as file:

writer = csv.writer(file)
header = ["start_detection", "end_detection", "label", "confidence", "hr"]
writer = csv.writer(file)
header = ["start_detection", "end_detection", "label", "confidence", "hr"]

writer.writerow(header)
writer.writerows(rows_for_csv)
writer.writerow(header)
writer.writerows(rows_for_csv)
else:
file_analyzed = os.path.basename(outname)
message = f"No detection has been made for {file_analyzed}"
print(message)
logging.info(message)


def analyzeFile(
Expand Down Expand Up @@ -148,6 +155,7 @@ def analyzeFile(
)

pred_audioclip_array, pred_hr_array = predict(predLoader, model, device)

write_results(pred_audioclip_array, pred_hr_array, outpath, min_hr, min_conf)

# Give the tim it took to analyze file
Expand Down Expand Up @@ -189,7 +197,7 @@ def analyzeFile(
parser.add_argument(
"--min_conf",
help="Minimum value for model confidence to take detection in",
default=0.95,
default=0.99,
required=False,
type=int,
)
Expand Down

0 comments on commit 8b29db7

Please sign in to comment.