Skip to content

Commit

Permalink
Mac signed installer (#407)
Browse files Browse the repository at this point in the history
* remove build files

* ignore optional import warning

* small review update

---------

Co-authored-by: Josef Haupt <josef.haupt@phil.tu-chemnitz.de>
  • Loading branch information
Josef-Haupt and Josef Haupt authored Aug 14, 2024
1 parent 5f658d5 commit 0d30f5e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 220 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ foo*
installers/
desktop.ini
*.iss
*deploy*

# Custom classifier
checkpoints/custom/
Expand All @@ -34,7 +35,7 @@ __pycache__/

# Distribution / packaging
.Python
build/
build*
develop-eggs/
dist/
downloads/
Expand All @@ -58,8 +59,6 @@ MANIFEST
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
!BirdNET-Analyzer-mac.spec
!BirdNET-Analyzer-win.spec

# Installer logs
pip-log.txt
Expand Down
55 changes: 0 additions & 55 deletions BirdNET-Analyzer-mac.spec

This file was deleted.

122 changes: 0 additions & 122 deletions BirdNET-Analyzer-win.spec

This file was deleted.

30 changes: 0 additions & 30 deletions deploy.py

This file was deleted.

19 changes: 13 additions & 6 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from pathlib import Path
from functools import partial

import config as cfg


if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
# divert stdout & stderr to logs.txt file since we have no console when deployed
userdir = Path.home()
Expand Down Expand Up @@ -34,7 +37,6 @@
import webview

import analyze
import config as cfg
import segments
import species
import utils
Expand Down Expand Up @@ -1559,7 +1561,7 @@ def collect_files(directory):

def create_log_plot(positives, negatives, fig_num=None):
import matplotlib.pyplot as plt
import sklearn
from sklearn import linear_model
import numpy as np
from scipy.special import expit

Expand All @@ -1580,13 +1582,18 @@ def create_log_plot(positives, negatives, fig_num=None):

for fl in positives + negatives:
try:
x_vals.append(float(os.path.basename(fl).split("_", 1)[0]))
x_val = float(os.path.basename(fl).split("_", 1)[0])

if 0 < x_val > 1:
continue

x_vals.append(x_val)
y_val.append(1 if fl in positives else 0)
except ValueError:
pass

if (len(positives) + len(negatives)) >= 2 and len(set(y_val)) > 1:
log_model = sklearn.linear_model.LogisticRegression(C=55)
log_model = linear_model.LogisticRegression(C=55)
log_model.fit([[x] for x in x_vals], y_val)
Xs = np.linspace(0, 10, 200)
Ys = expit(Xs * log_model.coef_ + log_model.intercept_).ravel()
Expand Down Expand Up @@ -1615,7 +1622,7 @@ def create_log_plot(positives, negatives, fig_num=None):
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
ax.legend(loc="center left", bbox_to_anchor=(1, 0.5))

if len(y_val) > 0:
ax.scatter(x_vals, y_val, 2)

Expand Down Expand Up @@ -1796,7 +1803,7 @@ def update_review(next_review_state: dict, selected_species: str = None):
update_dict |= {review_item_col: gr.Column(visible=False), no_samles_label: gr.Label(visible=True)}

return update_dict

def toggle_autoplay(value):
return gr.Audio(autoplay=value)

Expand Down
10 changes: 7 additions & 3 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# NOTE: we have to use TFLite if we want to use
# the metadata model or want to extract embeddings
try:
import tflite_runtime.interpreter as tflite
import tflite_runtime.interpreter as tflite # type: ignore
except ModuleNotFoundError:
from tensorflow import lite as tflite
if not cfg.MODEL_PATH.endswith(".tflite"):
Expand All @@ -49,7 +49,9 @@ def loadModel(class_output=True):
# Do we have to load the tflite or protobuf model?
if cfg.MODEL_PATH.endswith(".tflite"):
# Load TFLite model and allocate tensors.
INTERPRETER = tflite.Interpreter(model_path=os.path.join(SCRIPT_DIR, cfg.MODEL_PATH), num_threads=cfg.TFLITE_THREADS)
INTERPRETER = tflite.Interpreter(
model_path=os.path.join(SCRIPT_DIR, cfg.MODEL_PATH), num_threads=cfg.TFLITE_THREADS
)
INTERPRETER.allocate_tensors()

# Get input and output tensors.
Expand Down Expand Up @@ -114,7 +116,9 @@ def loadMetaModel():
global M_OUTPUT_LAYER_INDEX

# Load TFLite model and allocate tensors.
M_INTERPRETER = tflite.Interpreter(model_path=os.path.join(SCRIPT_DIR, cfg.MDATA_MODEL_PATH), num_threads=cfg.TFLITE_THREADS)
M_INTERPRETER = tflite.Interpreter(
model_path=os.path.join(SCRIPT_DIR, cfg.MDATA_MODEL_PATH), num_threads=cfg.TFLITE_THREADS
)
M_INTERPRETER.allocate_tensors()

# Get input and output tensors.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ librosa==0.9.2
resampy
tensorflow==2.15.0
gradio
webview
pywebview
tqdm
bottle
requests

0 comments on commit 0d30f5e

Please sign in to comment.