Skip to content

Commit

Permalink
Merge branch 'Birdnet2.4' of https://github.com/Mattk70/Chirpity-Elec…
Browse files Browse the repository at this point in the history
…tron into Birdnet2.4
  • Loading branch information
Mattk70 committed Jan 22, 2024
2 parents f389ee1 + 4044781 commit 6621a17
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Help/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<!-- </tr>-->
<tr>
<th>Search for</th>
<td><p><b>Migrants and Owls</b>. Just report detections relating to these species' calls (song detections are
<td><p><b>Birds in your Region</b>. Exclude birds unlikely to be found in your location.</p>
<p><b>Nocturnal Birds</b>. Just report detections relating to these species' calls (song detections are
excluded).</p>
<p><b>All birds</b>. Include birdsong as well as calls, also includes species not known to call at night.
</p>
Expand Down
21 changes: 11 additions & 10 deletions js/BirdNet2.4.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const tf = require('@tensorflow/tfjs-node');
const fs = require('node:fs');
const path = require('node:path');
let DEBUG = false;
let DEBUG = true;
let BACKEND;

//GLOBALS
Expand Down Expand Up @@ -135,7 +135,7 @@ break;
if (DEBUG) {
console.log(`Setting list to ${myModel.list}`);
}
myModel.setList();
await myModel.setList();
postMessage({
message: "update-list",
blocked: BLOCKED_IDS,
Expand Down Expand Up @@ -178,7 +178,9 @@ class Model {
{ weightPathPrefix: this.appPath });
this.model_loaded = true;
this.inputShape = [...this.model.inputs[0].shape];
this.metadata_model = await tf.loadGraphModel(path.join(this.appPath, 'mdata', 'model.json'));
const mdata_model_path = this.appPath + 'mdata/model.json'
this.metadata_model = await tf.loadGraphModel(mdata_model_path,
);
await this.setList();
}
}
Expand Down Expand Up @@ -211,16 +213,15 @@ class Model {
const mdata_prediction = this.metadata_model.predict(this.mdata_input);
const mdata_probs = await mdata_prediction.data();
const mdata_probs_sorted = mdata_probs.slice().sort().reverse();
console.log('<b>Most common species @ (' + lat + '/' + lon + ') in week ' + week + ':</b>');
let count = 0
for (let i = 0; i < mdata_probs_sorted.length; i++) {
const index = mdata_probs.indexOf(mdata_probs_sorted[i]);
if (mdata_probs_sorted[i] > 0.004) {
for (let i = 0; i < mdata_probs.length; i++) {
if (mdata_probs[i] > 0.004) {
count++;
console.log(this.labels[index] + ': ' + mdata_probs_sorted[i]);
DEBUG && console.log("including:", this.labels[i] + ': ' + mdata_probs[i]);
} else {
// Hack to add Dotterel
if (! this.labels[index].includes('Dotterel')) BLOCKED_IDS.push(index)
DEBUG && console.log("Excluding:", this.labels[i] + ': ' + mdata_probs[i]);
// Hack to add Dotterel??
if (! this.labels[i].includes('Dotterel')) BLOCKED_IDS.push(i)
}
}
console.log('Total species considered at this location: ', count)
Expand Down
9 changes: 5 additions & 4 deletions js/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,11 @@ class Model {
this.model_loaded = true;

this.inputShape = [...this.model.inputs[0].shape];
this.metadata_model = await tf.loadGraphModel(path.join(
this.appPath, '..', 'BirdNET_GLOBAL_6K_V2.4_Model_TFJS', 'static', 'model', 'mdata', 'model.json'
));
this.mdata_labels = JSON.parse(fs.readFileSync(path.join(__dirname, `..`, 'BirdNET_GLOBAL_6K_V2.4_Model_TFJS', 'static', 'model', 'labels.json'), "utf8"));
this.metadata_model = await tf.loadGraphModel(
this.appPath + '../BirdNET_GLOBAL_6K_V2.4_Model_TFJS/static/model/mdata/model.json'
);
const mdata_label_path = path.join(__dirname, '..','BirdNET_GLOBAL_6K_V2.4_Model_TFJS','static','model','labels.json')
this.mdata_labels = JSON.parse(fs.readFileSync(mdata_label_path, "utf8"));
await this.setList();
}
}
Expand Down

0 comments on commit 6621a17

Please sign in to comment.