diff --git a/README.md b/README.md index dc440b8..796a8c9 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,33 @@ pip3 install -r requirements-mac.txt plaidml-setup ``` -4. Configure environment variables: +4. Configure environment variables in the run script: ```sh export KERAS_BACKEND="plaidml.keras.backend" export tg_token="Your telegram token here" ``` + +### Windows (CUDA) + +1. Setup Python + +```powershell +python3.9 -m venv venv +.\venv\Scripts\activate +pip install -r requirements-win-cuda.txt +``` + +2. Install CUDA + +* Install NVIDIA Drivers: https://www.nvidia.com/drivers +* Install CUDA **11.2** (for TensorFlow 2.7.0): https://developer.nvidia.com/cuda-toolkit-archive +* Download cuDNN **8.1**: https://developer.nvidia.com/rdp/cudnn-archive + * Copy folders in `cudnn-11.2-windows-x64-v8.1.1.33\cuda` to `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2` +* Restart IntelliJ IDEA + +3. Check Device List + +```shell +python -c "from tensorflow.python.client import device_lib; print(device_lib.list_local_devices())" +``` diff --git a/requirements-win-cuda.txt b/requirements-win-cuda.txt new file mode 100644 index 0000000..be722db --- /dev/null +++ b/requirements-win-cuda.txt @@ -0,0 +1,5 @@ + +tensorflow==2.7.0 +inaSpeechSegmenter==0.6.8 + +python-telegram-bot diff --git a/src/bot.py b/src/bot.py index e643e3e..f1dccf8 100644 --- a/src/bot.py +++ b/src/bot.py @@ -1,17 +1,12 @@ -import os +import warnings from datetime import datetime from pathlib import Path + from telegram import Update, Message from telegram.ext import Updater, CallbackContext, Dispatcher, CommandHandler, MessageHandler, \ Filters -os.environ['KERAS_BACKEND'] = "plaidml.keras.backend" - -import keras - -from inaSpeechSegmenter import * from ina_main import * -import warnings warnings.filterwarnings("ignore") diff --git a/src/ina_main.py b/src/ina_main.py index 331d355..50109a3 100644 --- a/src/ina_main.py +++ b/src/ina_main.py @@ -2,31 +2,19 @@ from __future__ import annotations import io import os -import shutil -import sys import tempfile import time -import wave -from dataclasses import dataclass - -from PIL import Image +import warnings from subprocess import Popen, PIPE from typing import NamedTuple, Callable import matplotlib.pyplot as plt import numpy as np import scipy.io.wavfile -from matplotlib.figure import Figure, Axes -from numpy import ndarray - -os.environ['KERAS_BACKEND'] = "plaidml.keras.backend" - -import keras -from keras import backend - -import tensorflow as tf +from PIL import Image from inaSpeechSegmenter import * from inaSpeechSegmenter.segmenter import featGenerator +from matplotlib.figure import Figure, Axes class ResultFrame(NamedTuple): @@ -175,21 +163,30 @@ def get_result_percentages(result: Result) -> tuple[float, float, float]: return f, m, 1 - f - m -# def test(): -# results: BatchResults = BatchResults( -# [Result([ResultFrame('female', 0.0, 10.48), ResultFrame('male', 10.48, 12.780000000000001)], -# '../test.csv')], -# 1.7032792568206787, 1.7032792568206787, 1, -# [('../test.csv', 0)]) -# -# with draw_result('../test.mp3', results.results[0]) as buf: -# show_image_buffer(buf) -# print(get_result_percentages(results.results[0])) -# -# # seg = Segmenter() -# # print(process(seg, ['../test.mp3'])) +def test(): + # results: BatchResults = BatchResults( + # [Result([ResultFrame('female', 0.0, 10.48), ResultFrame('male', 10.48, 12.780000000000001)], + # '../test.csv')], + # 1.7032792568206787, 1.7032792568206787, 1, + # [('../test.csv', 0)]) + + warnings.filterwarnings("ignore") + seg = Segmenter() + + # Warmup run + results = process(seg, ['../test.mp3']) + print(results) + + # Actual run + results = process(seg, ['../test.mp3']) + print(results) + + # Draw results + with draw_result('../test.mp3', results.results[0]) as buf: + show_image_buffer(buf) + print(get_result_percentages(results.results[0])) + if __name__ == '__main__': - # to_wav('../audio_tmp/2021-12-22 05-32 leph1art5.mp3', print) - # test() + test() pass