https://drive.google.com/file/d/1AlDYFDqY_1tmhP-kwDVurIIRUNrMD5KJ/view?usp=sharing
# MACOS
python3 -m venv venv
source ./venv/bin/activate
pip install -r requirements.txt
CLIENT_ID=
CLIENT_SECRET=
SUPABASE_URL=
SUPABASE_API_KEY=
SPOTIFY_ACCESS_TOKEN=
Most recent time-series data is available at: time_series_data/datasets/music-listening-data-23-12-24-8AM.csv
this has been downloaded from Supabase
- The Pytesseract OCR wrapper is used to collect data on screen
A custom YOLO model was trained on 'focused' and 'distracted' images which can then be used to track the user's attention level
Notebooks used for training are included in:
attention_detection/attention_model_training_yolov5.ipynb
attention_detection/attention_model_training_yolov8.ipynb
Notebook for Model Testing
attention_detection/model_test.ipynb
These can be run in a jupyter notebook which avoids some of the issues presented by OpenCV in MacOS environment by using ipywidgets.
Models A total of 5 different models were trained, the weights for each of these models are stored as:
attention_detection/model_iterations/v5/weights/best.pt
attention_detection/model_iterations/v4/weights/best.pt
etc.
- Model 1 was trained on Yolov5s with 75 images per class ["focused","distracted"] over ~100 epochs
- Model 2 was trained on Yolov8n with 75 images per class over 500 epochs
- Model 3 was trained on Yolov8n with 200 images per class over 20 epochs
- Model 4 was trained on Yolov8n with 200 images per class over 100 epochs
- Model 5 was trained on Yolov8n with 200 images per class over 350 epochs
Model 5 showed the most optimal performance and was applied for the majority of attention data collection tasks.
- 7 experiments were defined to collect data for training the YOLO attention detection model, 200 images were collected for each class 'focused' and 'distracted'
- 7 experiments include 4 experiments to collect 'focused' image classes: report-writing (focused/100imgs), research (focused/75imgs), programming (focused/25imgs), planning (focused/10imgs)
- 3 experiments to collect 'distracted' image classes: highly-distracted (distracted/105imgs), distracted (distracted/80imgs), semi-distracted (distracted/15 imgs)
Notebooks used for data collection are included in:
attention_detection/data_collection_images.ipynb
A few sample images are included in
attention_detection/exps
however the full dataset is not uploaded to GitHub (stored on local device).
The full dataset of labels is included in attention_detection/training_data/labels
which was used in training models v3-v5.
- Text detection function
detect_text()
is kept inOCR/detect_screen_text.py
which can then be imported into relevant files e.g. streamlit app - The number of on-screen words is detected using
detect_text()
- The number of words is then inserted into a column in a Supabase table along with a timestamp and several other recorded metrics
Code available in: OCR/detect_screen_text.py
Similary to detect_text()
the attention detection model was then used to collect time series data, inserting either a DISTRACTED or FOCUSED state, the class score and the model version into the Supabase table along with the timestamp, previously mentioned text reading and song data:
- In conjunction with data collected through the laptop's hardware data is also collected through Spotify's API
- Using OAuth Authorization and
spotipy
the user's currently playing song is also included in the table INSERT, which will allow us to see how the currently playing song influences attention.
Code available in: live_data_collection.py
and music_integration/spotify_functions.py
python3 live_data_collection.py
Along with time-series data collection music metadata is collected:
- Lyrics are extracted from Genius API using BeautifulSoup
- A lyricalness measure is computed using this data
Code available in:
music_integration/lyricalness/compute_lyricalness.py
- Song BPM data is collected using artist & track name and the deezer client's search functionality
Code available in: music_integration/bpm/get_bpm.py
and music_integration/deezer_functions.py
Analysis is performed on the collected lyrics data in order to define the lyricalness metric.
Analysis is performed on the collected BPM data in order to define the average values to fill in missing data.
The available data stored in Supabase provides enough resources to investigate the correlation between lyrics, BPM, on-screen text and attention levels. The data is downloaded locally to a csv and some pre-processing steps are applied to prepare it for analysis (i.e. filling empty values using averages).
A random forest classifer is then trained on this data and the results are used to investigate the importance of different metrics on attention:
The respective feature importances are:
- Amount of text = 0.5416286
- BPM = 0.21180063
- Lyrics = 0.24657078
The effect of lyrics has a stronger influence on focus than BPM - therefore when making reccommendations to the user this should be weighted more strongly.
It makes sense the amount of text on screen correlates the most strongly with focus, as focus is likely to be much higher when more text is on screen as tasks that require a high degree of focus such as reading or writing are likely taking place.
- User will provide a link to a public playlist (this will only require the client credientials workflow)
- Tracks will be ranked according to current environmental conditions (user attention + volume of onscreen text) and a song will be recommended.
- This creates a foundation for any next steps (e.g. controlling user's spotify playback)
Uses user attention + text on screen to create song recommendations:
# Streamlit Live Plot for Attention:
streamlit run live_music_recommendations_with_attention.py
Uses simpler lyricalness to rank songs (no attention included):
# Streamlit Live Plot for Attention:
streamlit run live_music_recommendations.py
- This version of the code will get either the user's current queue or a user's playlist. The code will then perform the same ranking approach.
# Streamlit Live Plot for Attention:
streamlit run live_music_recommendations.py
Will show a live plot for attention - using custom yolov8 model trained on focused & unfocused data
# Streamlit Both Live Plots
streamlit run st_live_plots.py
Plots live plots for both attention & text on screen - can be useful for observing relationships between amount of text on screen & how focused the user is
!git clone https://github.com/tzutalin/labelImg
!pip install pyqt5 lxml --upgrade
!cd labelImg && pyrcc5 -o libs/resources.py resources.qrc
- A collection of music APIs, databases, and related tools
- Spotify OAuth: Automating Discover Weekly Playlist - Full Tutorial - YouTube
- Python Spotify API #3 - Retrieving Users Songs - YouTube
- Deep Drowsiness Detection using YOLO, Pytorch and Python - YouTube
- Train Yolov8 object detection on a custom dataset | Step by step guide | Computer vision tutorial - YouTube