Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added mgw #10

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 2 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,14 @@ The `generate` command accepts one input file or one input folder and one output
#### Usage

```
generate [-F|--format] [-c|--config <config-file>] <input-file> <output-directory>
generate <input-file> <output-directory>
<input-file> The file to generate embeddings for
<output-directory> The directory to write the embeddings to
-F|--format [csv|parquet] The format of the embeddings file: `CSV`` or `Parquet``
-c|--config <config-file> An optional configuration file to use
```

#### Configuration file

```yaml
hop_length_seconds: 5.0
```

#### Examples

Expand Down Expand Up @@ -75,60 +71,9 @@ classify [-F|--format] [-c|--config <config-file> ] <input-file> <output-directo
#### Configuration file

```yaml
hop_length_seconds: 5.0
classifiers:
- name: "classifier1"
tags: ["tag1", "tag2"]
# base64 encoded model
model: "asd321jhfsdhk438asdmlfas89i3mnlksf..."
- name: "classifier2"
tags: ["tag3", "tag4"]
# base64 encoded model
model: "..."

```

#### Example

```bash
cd /data
curl -o audio.wav https://api.ecosounds.org/audio_recordings/123.wav
docker run -v /data:/data perch-runner classify -c /data/config.yml /data/audio.wav /data/output
```

### Distance

The `distance` command accepts one input file, one output directory, and a query file.

- The query file must be an audio file that is 5 seconds long.
- The output of this command is the same as the output of the `generate` command,
but with an additional column `distance` that represents the distance between the
query and the sample.

#### Usage

```
distance [-F|--format] [-c|--config <config-file> ] <input-file> <query-file> <output-directory>
<input-file> The file to generate embeddings for
<output-directory> The directory to write the embeddings to
<query-file> The file to use as the query
-c|--config <config-file> An optional configuration file to use
```

#### Configuration file

```yaml
hop_length_seconds: 5.0
classifier: keras_saved_model_path
```

#### Example

```bash
cd /data
curl -o audio.wav https://api.ecosounds.org/audio_recordings/123.wav
curl -o query.wav https://api.ecosounds.org/audio_recordings/456/media.wav?start=10&end=15
docker run -v /data:/data perch-runner distance -c /data/config.yml /data/audio.wav /data/query.wav /data/output
```


## Batch Mode
Expand Down
Binary file added models/mgw/mgw_v05.keras
Binary file not shown.
1 change: 1 addition & 0 deletions models/mgw/mgw_v05.keras.labels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["mgw", "negative"]
7 changes: 5 additions & 2 deletions scripts/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ Notes
1. Open a terminal window
2. Change directory to this scripts directory
3. Run the following command:
- windows: `powershell -ExecutionPolicy Bypass -File analyze.ps1 classify [path_to_audio_folder] [path_to_embeddings_folder] 'pw'`
- linux or intel mac: `./analyze.sh classify [path_to_embeddings_output_folder] [path_to_classifications_output_folder] 'pw'`
- windows: `powershell -ExecutionPolicy Bypass -File analyze.ps1 classify [path_to_audio_folder] [path_to_embeddings_folder] '[recognizer_id]'`
- linux or intel mac: `./analyze.sh classify [path_to_embeddings_output_folder] [path_to_classifications_output_folder] '[recognizer_id]'`
- where [recognizer_id] is one of
- 'pw' (Plains wanderer)
- 'mgw' (Mukarrthippi graw wren)


Notes
Expand Down
3 changes: 2 additions & 1 deletion scripts/analyze.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ $config = ""
$recognizer_configs = @{
"pw" = "pw.classify.yml"
"cgw" = "cgw.classify.yml"
"mgw" = "mgw.classify.yml"
}

# Check if the recognizer argument has been provided
if ($recognizer) {
if ($recognizer -and $analysis -eq "classify") {
# Check if the provided recognizer is supported and set the config variable
if ($recognizer_configs.ContainsKey($recognizer)) {
$config = $recognizer_configs[$recognizer]
Expand Down
38 changes: 22 additions & 16 deletions scripts/analyze.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,33 @@ fi
# Initialize command with a default value
command=""

declare -A recognizer_configs
recognizer_configs["pw"]="pw.classify.yml"
recognizer_configs["cgw"]="cgw.classify.yml"

# Check if the recognizer argument has been provided
if [[ -n "$recognizer" ]]; then
# Check if the provided recognizer is supported and set the config variable
if [[ -n ${recognizer_configs[$recognizer]} ]]; then
config=${recognizer_configs[$recognizer]}
echo "Using config file: $config"
config="--config $config"
# if analysis is 'classify'
if [[ "$analysis" == "classify" ]]; then
declare -A recognizer_configs
recognizer_configs["pw"]="pw.classify.yml"
recognizer_configs["cgw"]="cgw.classify.yml"
recognizer_configs["mgw"]="mgw.classify.yml"

# Check if the recognizer argument has been provided
if [[ -n "$recognizer" ]]; then
# Check if the provided recognizer is supported and set the config variable
if [[ -n ${recognizer_configs[$recognizer]} ]]; then
config=${recognizer_configs[$recognizer]}
echo "Using config file: $config"
config="--config $config"
else
echo "Recognizer $recognizer not supported"
exit 1
fi
else
echo "Recognizer $recognizer not supported"
exit 1
# Set config variable to an empty string if no recognizer is provided
config=""
fi
else
# Set config variable to an empty string if no recognizer is provided
config=""
fi




# paths to things inside the container, to be mounted

# Determine input container path
Expand Down
2 changes: 2 additions & 0 deletions src/default_configs/mgw.classify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
classifier: mgw
inherit: classify.yml
5 changes: 3 additions & 2 deletions tests/docker_tests/test_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
["pwsh", "-ExecutionPolicy", "Bypass", "-File", "./scripts/analyze.ps1"]
]

index = 1
index = 0
#image = "pr10:latest"

def test_analyze_script_classify():

Expand All @@ -19,7 +20,7 @@ def test_analyze_script_classify():
shutil.copy("tests/files/embeddings/100sec.parquet", two)

# Run the embed helper script
command = scripts[index] + ["classify", "./tests/input/", "./tests/output/", "pw"]
command = scripts[index] + ["classify", "./tests/input/", "./tests/output/", "mgw"]
print(f'running command: {" ".join(command)}')
subprocess.run(command, check=True)

Expand Down
Loading