forked from NERC-CEH/plankton_ml
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Drop scivision #1
Closed
Closed
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
724c096
don't move to gpu inside prepare_data
jmarshrossney 65cc62a
switch to src layout
jmarshrossney 9600b33
undo accidental nesting of test folder
jmarshrossney 5807fed
run black
jmarshrossney 49b1d21
change python -m pytest to pytest in README
jmarshrossney 70b82c2
update python version; deps in pyproject
jmarshrossney bc7c43b
load scivision model from forked repo
jmarshrossney 6c7aaf2
move vector store; minor adjustments
jmarshrossney c03d9f2
test install/setup using pip and conda
jmarshrossney d84c768
minimally remove scivision from ImageEmbeddings notebook
jmarshrossney daa6733
update remainder of ImageEmbeddings.md
jmarshrossney 32bdc1f
add matplotlib dependence for notebooks
jmarshrossney 2bf3586
run black; update flake8 config to ignore directories
jmarshrossney a21719c
Merge branch 'main' into drop-scivision
metazool 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
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
**/__pycache__/ | ||
vectors/ | ||
*.ipynb | ||
*.egg-info/ | ||
venv/ |
This file contains 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 @@ | ||
3.12 |
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,22 +1,25 @@ | ||
name: cyto_39 | ||
name: cyto_ml | ||
channels: | ||
- pytorch | ||
- conda-forge | ||
- defaults | ||
channel_priority: flexible | ||
dependencies: | ||
- python=3.9 | ||
- pytorch=1.10.0 | ||
- mkl=2024.0 | ||
- chromadb=0.5.3 | ||
- python=3.12 | ||
- pytorch | ||
- black | ||
- chromadb | ||
- flake8 | ||
- intake-xarray | ||
- scikit-image | ||
- intake=0.7 | ||
- isort | ||
- jupyterlab | ||
- jupytext | ||
- pandas | ||
- pytest | ||
- python-dotenv | ||
- s3fs | ||
- jupyterlab | ||
- jupytext | ||
- scikit-image | ||
- xarray | ||
- pip | ||
- pip: | ||
- scivision | ||
- git+https://github.com/alan-turing-institute/plankton-cefas-scivision@main | ||
- git+https://github.com/jmarshrossney/resnet50-cefas |
This file contains 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 |
---|---|---|
@@ -1,12 +1,39 @@ | ||
[build-system] | ||
requires = ["setuptools >= 61.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "cyto_ml" | ||
version = "0.1" | ||
version = "0.2.0" | ||
requires-python = ">=3.12" | ||
description = "This package supports the processing and analysis of plankton sample data" | ||
readme = "README.md" | ||
requires-python = "==3.9.*" | ||
dependencies = [ | ||
"chromadb", | ||
"intake==0.7.0", | ||
"intake-xarray", | ||
"pandas", | ||
"python-dotenv", | ||
"s3fs", | ||
"scikit-image", # secretly required by intake-xarray as default reader | ||
"torch", | ||
"xarray", | ||
"resnet50-cefas@git+https://github.com/jmarshrossney/resnet50-cefas", | ||
] | ||
|
||
[tool.setuptools] | ||
py-modules = [] | ||
[project.optional-dependencies] | ||
jupyter = ["jupyterlab", "jupytext"] | ||
dev = ["pytest", "black", "flake8", "isort"] | ||
all = ["cyto_ml[jupyter,dev]"] | ||
|
||
[tool.jupytext] | ||
formats = "ipynb,md" | ||
|
||
[tool.pytest.ini_options] | ||
filterwarnings = [ | ||
"ignore::DeprecationWarning", | ||
] | ||
|
||
[tool.black] | ||
target-version = ["py312"] | ||
line-length = 88 |
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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,35 @@ | ||
import torch | ||
from torchvision.transforms.v2.functional import to_image, to_dtype | ||
from xarray import DataArray | ||
|
||
def prepare_image(image: DataArray): | ||
""" | ||
Take an xarray of image data and prepare it to pass through the model | ||
a) Converts the image data to a PyTorch tensor | ||
b) Accepts a single image or batch (no need for torch.stack) | ||
""" | ||
# Computes the DataArray and returns a numpy array | ||
image_numpy = image.to_numpy() | ||
|
||
# Convert the image data to a PyTorch tensor | ||
tensor_image = to_dtype( | ||
to_image(image_numpy), # permutes HWC -> CHW | ||
torch.float32, | ||
scale=True, # rescales [0, 255] -> [0, 1] | ||
) | ||
Comment on lines
+16
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
assert torch.all((tensor_image >= 0.0) & (tensor_image <= 1.0)) | ||
|
||
if tensor_image.dim() == 3: | ||
# Single image, add a batch dimension | ||
tensor_image = tensor_image.unsqueeze(0) | ||
|
||
assert tensor_image.dim() == 4 | ||
|
||
return tensor_image | ||
|
||
|
||
def flat_embeddings(features: torch.Tensor): | ||
"""Utility function that takes the features returned by the model in truncate_model | ||
And flattens them into a list suitable for storing in a vector database""" | ||
# TODO: this only returns the 0th tensor in the batch...why? | ||
return features[0].detach().tolist() |
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it fails for me with
strict
priority