-
Notifications
You must be signed in to change notification settings - Fork 22
Data compression for screen data #81
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
Open
schewskone
wants to merge
32
commits into
sensorium-competition:main
Choose a base branch
from
schewskone:compressed_data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
1dae16f
added support for compressed data formats and added tests for jpg ima…
schewskone f2b906f
style: auto-format with black and isort
invalid-email-address 406b9a9
added torchcodec to requirements
schewskone 34c88c7
added ffmpeg to github actions setup
schewskone 902f3ca
Merge branch 'sensorium-competition:main' into compressed_data
schewskone c009980
replaced inproper usage of torchvision functions for transforms on no…
schewskone 8a5314c
style: auto-format with black and isort
invalid-email-address 76ded2d
added option to read stimulis via image_names instead of index_naming…
schewskone ad1f7cb
style: auto-format with black and isort
invalid-email-address 9a525b6
adjusted variable namings
schewskone 98c9924
Merge remote-tracking branch 'origin/ToTensor_fix' into compressed_data
schewskone 721d554
interpolation no longer returns valid argument
schewskone df018f7
style: auto-format with black and isort
invalid-email-address c07759d
added formating function that handles multi channel data and added ve…
schewskone a350f82
formatting
schewskone e95bd0d
Merge branch 'compressed_data' of github.com:schewskone/experanto int…
schewskone ff24676
cleared notebook output
schewskone 6fc95cf
changed shape to (T,C,H,W), added channels and image_names to metafil…
schewskone 8da38d7
style
schewskone f87e878
Merge branch 'main' into compressed_data. Merge gitignore from recent…
schewskone af94841
recombined normalization in datasets transforms and cleaned condition…
schewskone d18a9db
added unsqueze to transforms to make torchvision transform function o…
schewskone 7c8325e
style: auto-format with black and isort
invalid-email-address 8805869
merged pr#84
schewskone 1da304c
changed screen interpolation to enable sliced decoding instead of ful…
schewskone 0b75107
style: auto-format with black and isort
invalid-email-address 16a2a14
merged custom_interpolator from main
schewskone b3b0079
revised workflow setup and adjusted bug where indexing was performed …
schewskone 137295c
style: auto-format with black and isort
invalid-email-address 5cdc810
removed debug prints
schewskone 128efde
code review with copilot
schewskone 512a42b
style: auto-format with black and isort
invalid-email-address File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,3 +163,6 @@ cython_debug/ | |
|
|
||
| *.sif | ||
| *.bak | ||
|
|
||
| # local workflow testing | ||
| bin/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "5dc8ad24", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "### Showcase of interpolation on Experiment level for encoded videos and images in greyscale and RGB." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "e4aecde6", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# import dependencies\n", | ||
| "\n", | ||
| "%load_ext autoreload\n", | ||
| "%autoreload 2\n", | ||
| "%matplotlib inline\n", | ||
| "\n", | ||
| "import numpy as np\n", | ||
| "import matplotlib.pyplot as plt\n", | ||
| "import matplotlib.animation as animation\n", | ||
| "from IPython.display import HTML" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "9bc17dbb", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# get the experiment class from experanto \n", | ||
| "from experanto.experiment import Experiment\n", | ||
| "\n", | ||
| "# set experiment folder as root\n", | ||
| "root_folder = '../../allen-exporter/data/allen_data/experiment_951980471'\n", | ||
| "\n", | ||
| "# initialize experiment object\n", | ||
| "e = Experiment(root_folder)" | ||
schewskone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "2447e233", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "times = np.arange(310., 340., 0.5)\n", | ||
| "video = e.interpolate(times, device=\"screen\") # shape: (T, C, H, W)\n", | ||
| "\n", | ||
| "# Clip and convert to uint8 to avoid matplotlib clipping warnings\n", | ||
| "video = np.clip(video, 0, 255).astype(np.uint8)\n", | ||
| "video = video.transpose(0, 2, 3, 1) # (T, H, W, C)\n", | ||
| "\n", | ||
| "n_frames, height, width, channels = video.shape\n", | ||
| "print(f\"Video shape: {video.shape}\")\n", | ||
| "\n", | ||
| "# Handle grayscale vs color\n", | ||
| "is_grayscale = (channels == 1)\n", | ||
| "if is_grayscale:\n", | ||
| " video = video[..., 0] # Now shape: (T, H, W)\n", | ||
| "\n", | ||
| "fig, ax = plt.subplots()\n", | ||
| "\n", | ||
| "# Initialize with appropriate cmap\n", | ||
| "if is_grayscale:\n", | ||
| " img = ax.imshow(video[0], cmap='gray', vmin=0, vmax=255)\n", | ||
| "else:\n", | ||
| " img = ax.imshow(video[0])\n", | ||
| "\n", | ||
| "ax.axis('off')\n", | ||
| "\n", | ||
| "def update(frame):\n", | ||
| " img.set_array(video[frame])\n", | ||
| " ax.set_title(f'Frame {frame}')\n", | ||
| " return [img]\n", | ||
| "\n", | ||
| "ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=50, blit=True)\n", | ||
| "\n", | ||
| "plt.close(fig)\n", | ||
| "HTML(ani.to_jshtml())" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "129ae368", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "%%timeit\n", | ||
| "video = e.interpolate(times, device=\"screen\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "d58eaaeb", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "times = np.arange(4484., 4500., 0.5)\n", | ||
| "video = e.interpolate(times, device=\"screen\") # shape: (T, C, H, W)\n", | ||
| "\n", | ||
| "# Clip and convert to uint8 to avoid matplotlib clipping warnings\n", | ||
| "video = np.clip(video, 0, 255).astype(np.uint8)\n", | ||
| "video = video.transpose(0, 2, 3, 1) # (T, H, W, C)\n", | ||
| "\n", | ||
| "n_frames, height, width, channels = video.shape\n", | ||
| "print(f\"Video shape: {video.shape}\")\n", | ||
| "\n", | ||
| "# Handle grayscale vs color\n", | ||
| "is_grayscale = (channels == 1)\n", | ||
| "if is_grayscale:\n", | ||
| " video = video[..., 0] # Now shape: (T, H, W)\n", | ||
| "\n", | ||
| "fig, ax = plt.subplots()\n", | ||
| "\n", | ||
| "# Initialize with appropriate cmap\n", | ||
| "if is_grayscale:\n", | ||
| " img = ax.imshow(video[0], cmap='gray', vmin=0, vmax=255)\n", | ||
| "else:\n", | ||
| " img = ax.imshow(video[0])\n", | ||
| "\n", | ||
| "ax.axis('off')\n", | ||
| "\n", | ||
| "def update(frame):\n", | ||
| " img.set_array(video[frame])\n", | ||
| " ax.set_title(f'Frame {frame}')\n", | ||
| " return [img]\n", | ||
| "\n", | ||
| "ani = animation.FuncAnimation(fig, update, frames=n_frames, interval=50, blit=True)\n", | ||
| "\n", | ||
| "plt.close(fig)\n", | ||
| "HTML(ani.to_jshtml())" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "9a74eb40", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "%%timeit\n", | ||
| "video = e.interpolate(times, device=\"screen\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "ba9c51eb", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Download a test_rgb_image.jpg (1200x1900!) put it into the folder with other stimuli and run this to test rgb interpolation in the third cell.\n", | ||
| "# My test image : https://wallpapercave.com/download/1900x1200-wallpapers-wp9725873\n", | ||
| "# Also adjust number_channels to 3 inside the default.yaml config file\n", | ||
| "\n", | ||
| "import cv2\n", | ||
| "import numpy as np\n", | ||
| "import matplotlib.pyplot as plt\n", | ||
| "\n", | ||
| "# Load the JPEG image (in BGR format)\n", | ||
| "img = cv2.imread('../../../allen-exporter/data/allen_data/experiment_951980471/stimuli/test_rgb_image.jpg')\n", | ||
| "\n", | ||
| "# Optional: convert from BGR to RGB if you want\n", | ||
| "img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n", | ||
| "\n", | ||
| "# Plot the image\n", | ||
| "plt.imshow(img_rgb)\n", | ||
| "plt.axis('off') # hide axes\n", | ||
| "plt.show()\n", | ||
| "\n", | ||
| "# Save the image as a .npy file\n", | ||
| "np.save('../../../allen-exporter/data/allen_data/experiment_951980471/stimuli/im065.npy', img_rgb)\n" | ||
schewskone marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "2c52e9e3", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "experanto", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.12.8" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.