dsa-helpers 0.4__tar.gz → 0.4.dev1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {dsa_helpers-0.4/dsa_helpers.egg-info → dsa_helpers-0.4.dev1}/PKG-INFO +2 -8
  2. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/README.md +2 -4
  3. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/__init__.py +1 -1
  4. dsa_helpers-0.4.dev1/dsa_helpers/ml/__init__.py +2 -0
  5. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/mongo_utils.py +14 -10
  6. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1/dsa_helpers.egg-info}/PKG-INFO +2 -8
  7. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers.egg-info/SOURCES.txt +2 -12
  8. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers.egg-info/requires.txt +0 -4
  9. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/pyproject.toml +2 -6
  10. dsa_helpers-0.4.dev1/readthedocs.yaml +27 -0
  11. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/requirements.txt +1 -5
  12. dsa_helpers-0.4.dev1/tests/test.ipynb +79 -0
  13. dsa_helpers-0.4/dsa_helpers/ml/__init__.py +0 -2
  14. dsa_helpers-0.4/dsa_helpers/ml/datasets/SegFormerSegmentationDataset.py +0 -33
  15. dsa_helpers-0.4/dsa_helpers/ml/datasets/__init__.py +0 -3
  16. dsa_helpers-0.4/dsa_helpers/ml/datasets/utils.py +0 -42
  17. dsa_helpers-0.4/dsa_helpers/ml/metrics/__init__.py +0 -3
  18. dsa_helpers-0.4/dsa_helpers/ml/metrics/binary_dice_coefficient_metric.py +0 -24
  19. dsa_helpers-0.4/dsa_helpers/ml/transforms/__init__.py +0 -1
  20. dsa_helpers-0.4/dsa_helpers/ml/transforms/segformer_transforms.py +0 -23
  21. dsa_helpers-0.4/dsa_helpers/utils.py +0 -28
  22. dsa_helpers-0.4/tests/app/Dockerfile +0 -18
  23. dsa_helpers-0.4/tests/app/app.py +0 -55
  24. dsa_helpers-0.4/tests/docker-compose.yaml +0 -31
  25. dsa_helpers-0.4/tests/test.ipynb +0 -268
  26. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/.gitignore +0 -0
  27. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/LICENSE +0 -0
  28. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/app.py +0 -0
  29. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/dash/__init__.py +0 -0
  30. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/dash/header.py +0 -0
  31. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/dash/header_callbacks.py +0 -0
  32. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/girder_utils.py +0 -0
  33. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/image_utils.py +0 -0
  34. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/imread.py +0 -0
  35. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/imwrite.py +0 -0
  36. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/login.py +0 -0
  37. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/ml/object_detection/__init__.py +0 -0
  38. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/ml/object_detection/get_pearce_roi_images.py +0 -0
  39. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/ml/object_detection/tile_image.py +0 -0
  40. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers/ml/object_detection/utils.py +0 -0
  41. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers.egg-info/dependency_links.txt +0 -0
  42. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/dsa_helpers.egg-info/top_level.txt +0 -0
  43. {dsa_helpers-0.4 → dsa_helpers-0.4.dev1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dsa_helpers
3
- Version: 0.4
3
+ Version: 0.4.dev1
4
4
  Summary: Utility functions for working with the DSA girder client.
5
5
  Author-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
6
6
  Maintainer-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
@@ -22,10 +22,6 @@ Requires-Dist: dash
22
22
  Requires-Dist: dash_bootstrap_components
23
23
  Requires-Dist: shapely
24
24
  Requires-Dist: geopandas
25
- Requires-Dist: torch
26
- Requires-Dist: datasets
27
- Requires-Dist: transformers
28
- Requires-Dist: torchvision
29
25
 
30
26
  # Digital Slide Archive (DSA) Helpers
31
27
  Digital Slide Archive Python utility library.
@@ -40,11 +36,9 @@ This Python PyPI package is found [here](https://pypi.org/project/dsa-helpers/).
40
36
  1. Install requirements for building and distributing package:
41
37
  ```
42
38
  $ python3 -m pip install --upgrade build # for building package
43
- $ python3 -m pip install --upgrade twine # for uploading to PyPI
39
+ $ python3 -m pip install --upgrade build # for uploading to PyPI
44
40
  ```
45
41
  2. When ready to build:
46
42
  - Modify "pyproject.toml" file, change the "version" key to a different value than a version already pushed.
47
43
  - Run ```$ python3 -m build```. This will create a dist directory and put your new wheel and tar distribution files there.
48
44
  3. To install locally for development: ```$ pip3 install dist/dsa_helpers-*.whl```, choosing the wheel version you want to test.
49
- 4. Upload to PyPI using twine: ```python3 -m twine upload --repository pypi dist/*```
50
- * You can specify specific files to upload, the line above pushes everything in dist directory.
@@ -11,11 +11,9 @@ This Python PyPI package is found [here](https://pypi.org/project/dsa-helpers/).
11
11
  1. Install requirements for building and distributing package:
12
12
  ```
13
13
  $ python3 -m pip install --upgrade build # for building package
14
- $ python3 -m pip install --upgrade twine # for uploading to PyPI
14
+ $ python3 -m pip install --upgrade build # for uploading to PyPI
15
15
  ```
16
16
  2. When ready to build:
17
17
  - Modify "pyproject.toml" file, change the "version" key to a different value than a version already pushed.
18
18
  - Run ```$ python3 -m build```. This will create a dist directory and put your new wheel and tar distribution files there.
19
- 3. To install locally for development: ```$ pip3 install dist/dsa_helpers-*.whl```, choosing the wheel version you want to test.
20
- 4. Upload to PyPI using twine: ```python3 -m twine upload --repository pypi dist/*```
21
- * You can specify specific files to upload, the line above pushes everything in dist directory.
19
+ 3. To install locally for development: ```$ pip3 install dist/dsa_helpers-*.whl```, choosing the wheel version you want to test.
@@ -5,4 +5,4 @@ from .imwrite import imwrite
5
5
  # Modules that should be available.
6
6
  # from . import girder_utils, image_utils, dash
7
7
 
8
- __all__ = ["girder_utils", "image_utils", "dash", "ml"]
8
+ __all__ = ["girder_utils", "image_utils", "dash"]
@@ -0,0 +1,2 @@
1
+ # Modules that can be imported.
2
+ __all__ = ["object_detection"]
@@ -13,7 +13,7 @@ def get_mongo_client(
13
13
  username: str | None = None,
14
14
  password: str | None = None,
15
15
  port: int | None = None,
16
- ):
16
+ ) -> pymongo.MongoClient:
17
17
  """Get a mongo client by providing the key parts of the URL. By default
18
18
  when the parameters are not passed, it sets them to default values first
19
19
  by looking at key environment variables. If the environment variables are
@@ -36,7 +36,7 @@ def get_mongo_client(
36
36
  missing it will default to 27017.
37
37
 
38
38
  Returns:
39
- The mongo client.
39
+ pymongo.MongoClient: The mongo client.
40
40
 
41
41
  """
42
42
  if username is None:
@@ -67,7 +67,7 @@ def chunks(lst: list, n=500):
67
67
 
68
68
 
69
69
  def add_many_to_collection(
70
- mongo_collection,
70
+ mongo_collection: pymongo.collection.Collection,
71
71
  items: dict | list,
72
72
  key: str = "_id",
73
73
  ) -> dict[str | dict]:
@@ -75,7 +75,7 @@ def add_many_to_collection(
75
75
  user key.
76
76
 
77
77
  Args:
78
- mongo_collection: The mongo collection to add to.
78
+ mongo_collection (pymongo.collection.Collection): The mongo collection to add to.
79
79
  items (dict | list): The items to add to the collection.
80
80
  key (str): The key to use to identify the items.
81
81
 
@@ -89,8 +89,10 @@ def add_many_to_collection(
89
89
 
90
90
  operations = []
91
91
 
92
- for _id, item in items.items():
93
- operations.append(pymongo.UpdateOne({"_id": _id}, {"$set": item}, upsert=True))
92
+ for item in items:
93
+ operations.append(
94
+ pymongo.UpdateOne({"_id": item[key]}, {"$set": item}, upsert=True)
95
+ )
94
96
 
95
97
  for chunk in chunks(operations):
96
98
  _ = mongo_collection.bulk_write(chunk)
@@ -98,11 +100,13 @@ def add_many_to_collection(
98
100
  return items
99
101
 
100
102
 
101
- def get_img_from_db(mongo_db, img_id: str) -> Union[np.ndarray, None]:
103
+ def get_img_from_db(
104
+ mongo_db: pymongo.database.Database, img_id: str
105
+ ) -> Union[np.ndarray, None]:
102
106
  """Get an image from the database by its location id.
103
107
 
104
108
  Args:
105
- mongo_db: The mongo database.
109
+ mongo_db (pymongo.database.Database): The mongo database.
106
110
  img_loc (str): The image id in mongo.
107
111
 
108
112
  Returns:
@@ -127,13 +131,13 @@ def get_img_from_db(mongo_db, img_id: str) -> Union[np.ndarray, None]:
127
131
 
128
132
 
129
133
  def add_img_to_db(
130
- mongo_db,
134
+ mongo_db: pymongo.database.Database,
131
135
  img: Image.Image | np.ndarray,
132
136
  ) -> str:
133
137
  """Add an image to the database.
134
138
 
135
139
  Args:
136
- mongo_db: The mongo database.
140
+ mongo_db (pymongo.database.Database): The mongo database.
137
141
  img (np.ndarray or PIL.Image.Image): The image.
138
142
 
139
143
  Returns:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dsa_helpers
3
- Version: 0.4
3
+ Version: 0.4.dev1
4
4
  Summary: Utility functions for working with the DSA girder client.
5
5
  Author-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
6
6
  Maintainer-email: "Juan C. Vizcarra" <jvizcar@emory.edu>
@@ -22,10 +22,6 @@ Requires-Dist: dash
22
22
  Requires-Dist: dash_bootstrap_components
23
23
  Requires-Dist: shapely
24
24
  Requires-Dist: geopandas
25
- Requires-Dist: torch
26
- Requires-Dist: datasets
27
- Requires-Dist: transformers
28
- Requires-Dist: torchvision
29
25
 
30
26
  # Digital Slide Archive (DSA) Helpers
31
27
  Digital Slide Archive Python utility library.
@@ -40,11 +36,9 @@ This Python PyPI package is found [here](https://pypi.org/project/dsa-helpers/).
40
36
  1. Install requirements for building and distributing package:
41
37
  ```
42
38
  $ python3 -m pip install --upgrade build # for building package
43
- $ python3 -m pip install --upgrade twine # for uploading to PyPI
39
+ $ python3 -m pip install --upgrade build # for uploading to PyPI
44
40
  ```
45
41
  2. When ready to build:
46
42
  - Modify "pyproject.toml" file, change the "version" key to a different value than a version already pushed.
47
43
  - Run ```$ python3 -m build```. This will create a dist directory and put your new wheel and tar distribution files there.
48
44
  3. To install locally for development: ```$ pip3 install dist/dsa_helpers-*.whl```, choosing the wheel version you want to test.
49
- 4. Upload to PyPI using twine: ```python3 -m twine upload --repository pypi dist/*```
50
- * You can specify specific files to upload, the line above pushes everything in dist directory.
@@ -3,6 +3,7 @@ LICENSE
3
3
  README.md
4
4
  app.py
5
5
  pyproject.toml
6
+ readthedocs.yaml
6
7
  requirements.txt
7
8
  dsa_helpers/__init__.py
8
9
  dsa_helpers/girder_utils.py
@@ -11,7 +12,6 @@ dsa_helpers/imread.py
11
12
  dsa_helpers/imwrite.py
12
13
  dsa_helpers/login.py
13
14
  dsa_helpers/mongo_utils.py
14
- dsa_helpers/utils.py
15
15
  dsa_helpers.egg-info/PKG-INFO
16
16
  dsa_helpers.egg-info/SOURCES.txt
17
17
  dsa_helpers.egg-info/dependency_links.txt
@@ -21,18 +21,8 @@ dsa_helpers/dash/__init__.py
21
21
  dsa_helpers/dash/header.py
22
22
  dsa_helpers/dash/header_callbacks.py
23
23
  dsa_helpers/ml/__init__.py
24
- dsa_helpers/ml/datasets/SegFormerSegmentationDataset.py
25
- dsa_helpers/ml/datasets/__init__.py
26
- dsa_helpers/ml/datasets/utils.py
27
- dsa_helpers/ml/metrics/__init__.py
28
- dsa_helpers/ml/metrics/binary_dice_coefficient_metric.py
29
24
  dsa_helpers/ml/object_detection/__init__.py
30
25
  dsa_helpers/ml/object_detection/get_pearce_roi_images.py
31
26
  dsa_helpers/ml/object_detection/tile_image.py
32
27
  dsa_helpers/ml/object_detection/utils.py
33
- dsa_helpers/ml/transforms/__init__.py
34
- dsa_helpers/ml/transforms/segformer_transforms.py
35
- tests/docker-compose.yaml
36
- tests/test.ipynb
37
- tests/app/Dockerfile
38
- tests/app/app.py
28
+ tests/test.ipynb
@@ -9,7 +9,3 @@ dash
9
9
  dash_bootstrap_components
10
10
  shapely
11
11
  geopandas
12
- torch
13
- datasets
14
- transformers
15
- torchvision
@@ -14,11 +14,7 @@ dependencies = [
14
14
  'dash',
15
15
  'dash_bootstrap_components',
16
16
  'shapely',
17
- 'geopandas',
18
- "torch",
19
- "datasets",
20
- "transformers",
21
- "torchvision"
17
+ 'geopandas'
22
18
  ]
23
19
  name = "dsa_helpers"
24
20
  authors = [
@@ -35,7 +31,7 @@ classifiers = [
35
31
  "License :: OSI Approved :: MIT License",
36
32
  ]
37
33
  keywords = ["dsa", "girder", "girder_client"]
38
- version = "v0.4"
34
+ version = "v0.4dev1"
39
35
 
40
36
  [project.urls]
41
37
  Repository = "https://github.com/Gutman-Lab/dsa-python-utils"
@@ -0,0 +1,27 @@
1
+ # .readthedocs.yaml
2
+ # Read the Docs configuration file
3
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4
+
5
+ # Required
6
+ version: 2
7
+
8
+ # Set the OS, Python version and other tools you might need
9
+ build:
10
+ tools:
11
+ python: "3.9"
12
+
13
+ # Build documentation in the "docs/" directory with Sphinx
14
+ sphinx:
15
+ configuration: docs/conf.py
16
+
17
+ # Optionally build your docs in additional formats such as PDF and ePub
18
+ # formats:
19
+ # - pdf
20
+ # - epub
21
+
22
+ # Optional but recommended, declare the Python requirements required
23
+ # to build your documentation
24
+ # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
25
+ # python:
26
+ # install:
27
+ # - requirements: docs/requirements.txt
@@ -8,8 +8,4 @@ jupyter
8
8
  pillow
9
9
  dash
10
10
  dash_bootstrap_components
11
- python-dotenv
12
- torch
13
- datasets
14
- transformers
15
- torchvision
11
+ python-dotenv
@@ -0,0 +1,79 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# Test Python Package Build"
8
+ ]
9
+ },
10
+ {
11
+ "cell_type": "code",
12
+ "execution_count": 1,
13
+ "metadata": {},
14
+ "outputs": [],
15
+ "source": [
16
+ "# Import all modules.\n",
17
+ "from dsa_helpers import *"
18
+ ]
19
+ },
20
+ {
21
+ "cell_type": "markdown",
22
+ "metadata": {},
23
+ "source": [
24
+ "#### Authenticate girder client."
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 3,
30
+ "metadata": {},
31
+ "outputs": [],
32
+ "source": [
33
+ "gc = girder_utils.login(\"\")"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "markdown",
38
+ "metadata": {},
39
+ "source": [
40
+ "#### Get DSA items recursively"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "execution_count": null,
46
+ "metadata": {},
47
+ "outputs": [],
48
+ "source": [
49
+ "# Get items from a folder.\n",
50
+ "items = girder_utils.get_items(gc, \"\")\n",
51
+ "print(f\"Got {len(items)} items from folder.\")\n",
52
+ "\n",
53
+ "items = girder_utils.get_items(gc, \"\")\n",
54
+ "print(f\"Got {len(items)} items from collection.\")"
55
+ ]
56
+ }
57
+ ],
58
+ "metadata": {
59
+ "kernelspec": {
60
+ "display_name": "env",
61
+ "language": "python",
62
+ "name": "python3"
63
+ },
64
+ "language_info": {
65
+ "codemirror_mode": {
66
+ "name": "ipython",
67
+ "version": 3
68
+ },
69
+ "file_extension": ".py",
70
+ "mimetype": "text/x-python",
71
+ "name": "python",
72
+ "nbconvert_exporter": "python",
73
+ "pygments_lexer": "ipython3",
74
+ "version": "3.12.3"
75
+ }
76
+ },
77
+ "nbformat": 4,
78
+ "nbformat_minor": 2
79
+ }
@@ -1,2 +0,0 @@
1
- # Modules that can be imported.
2
- __all__ = ["object_detection", "datasets", "metrics", "transforms"]
@@ -1,33 +0,0 @@
1
- from torch.utils.data import Dataset
2
- import pandas as pd
3
- from PIL import Image
4
- import numpy as np
5
-
6
-
7
- class SegFormerSegmentationDataset(Dataset):
8
- """PyTorch dataset class for semantic segmentation using HuggingFaces SegFormer
9
- model.
10
-
11
- """
12
-
13
- def __init__(self, df: pd.DataFrame):
14
- """Initiate an instance of the segmentation dataset.
15
-
16
- Args:
17
- df (pandas.DataFrame): A pandas DataFrame with columns "fp" and "mask_fp".
18
-
19
- """
20
- self.image_files = df["fp"].tolist()
21
- self.mask_files = df["mask_fp"].tolist()
22
- self.df = df # store potential metadata
23
-
24
- def __len__(self):
25
- return len(self.image_files)
26
-
27
- def __getitem__(self, idx):
28
- # Get the filepath to the image and its mask.
29
- image_path = self.image_files[idx]
30
- mask_path = self.mask_files[idx]
31
-
32
- # Return image & mask as PIL images in a dictionary.
33
- return {"pixel_values": Image.open(image_path), "label": Image.open(mask_path)}
@@ -1,3 +0,0 @@
1
- from .SegFormerSegmentationDataset import SegFormerSegmentationDataset
2
-
3
- __all__ = ["SegFormerSegmentationDataset", "utils"]
@@ -1,42 +0,0 @@
1
- # Utility functions, usualy for creating Datasets in specific formats.
2
- import pandas as pd
3
- from .SegFormerSegmentationDataset import SegFormerSegmentationDataset
4
- from datasets import Dataset, Features, Image
5
-
6
-
7
- def dataset_generator(dataset):
8
- """Yield a dataset."""
9
- for item in dataset:
10
- yield item
11
-
12
-
13
- def create_segformer_segmentation_dataset(
14
- df: pd.DataFrame | str, low_memory: bool = True, transforms=None
15
- ):
16
- """Create a SegFormer segmentation dataset from a DataFrame.
17
-
18
- Args:
19
- df (pd.DataFrame | str): A pandas DataFrame with columns "fp" and "mask_fp" or a
20
- path to a CSV file.
21
- low_memory (bool): Whether to read the CSV file in low memory mode.
22
- transforms: A function that takes in a batch of samples (dictionary with
23
- pixel_values and label keys) and returns a transformed batch.
24
-
25
- Returns:
26
- A Dataset object to be used for HuggingFaces SegFormer model training.
27
-
28
- """
29
- if isinstance(df, str):
30
- df = pd.read_csv(df, low_memory=low_memory)
31
-
32
- dataset = SegFormerSegmentationDataset(df)
33
-
34
- dataset = Dataset.from_generator(
35
- generator=lambda: dataset_generator(dataset),
36
- features=Features({"pixel_values": Image(), "label": Image()}), # Example shape
37
- )
38
-
39
- if transforms is not None:
40
- dataset.set_transform(transforms)
41
-
42
- return dataset
@@ -1,3 +0,0 @@
1
- from .binary_dice_coefficient_metric import binary_dice_coefficient_metric
2
-
3
- __all__ = ["binary_dice_coefficient_metric"]
@@ -1,24 +0,0 @@
1
- import torch
2
- from torch import nn
3
- from ...utils import binary_dice_coefficient
4
-
5
-
6
- def binary_dice_coefficient_metric(eval_pred):
7
- with torch.no_grad():
8
- logits, labels = eval_pred # assumed both are numpy
9
-
10
- logits_tensor = torch.from_numpy(logits).cpu()
11
- labels_tensor = torch.from_numpy(labels).cpu()
12
-
13
- # Scale the logits to the size of the label.
14
- logits_tensor = nn.functional.interpolate(
15
- logits_tensor,
16
- size=labels.shape[-2:],
17
- mode="bilinear",
18
- align_corners=False,
19
- ).argmax(dim=1)
20
-
21
- pred_labels = logits_tensor.detach().numpy()
22
- labels = labels_tensor.numpy()
23
-
24
- return {"dice_coefficient": binary_dice_coefficient(pred_labels, labels)}
@@ -1 +0,0 @@
1
- __all__ = ["segformer_transforms"]
@@ -1,23 +0,0 @@
1
- from transformers import SegformerImageProcessor
2
- from torchvision.transforms import ColorJitter
3
-
4
-
5
- def train_transforms(example_batch):
6
- """Default transforms for training images."""
7
- processor = SegformerImageProcessor() # required for using SegFormer model.
8
- jitter = ColorJitter(brightness=0.25, contrast=0.25, saturation=0.25, hue=0.1)
9
-
10
- images = [jitter(x) for x in example_batch["pixel_values"]]
11
- labels = [x for x in example_batch["label"]]
12
- inputs = processor(images, labels)
13
- return inputs
14
-
15
-
16
- def val_transforms(example_batch):
17
- """Default transforms for validation images."""
18
- processor = SegformerImageProcessor() # required for using SegFormer model.
19
-
20
- images = [x for x in example_batch["pixel_values"]]
21
- labels = [x for x in example_batch["label"]]
22
- inputs = processor(images, labels)
23
- return inputs
@@ -1,28 +0,0 @@
1
- # Basic utility functions.
2
- import numpy as np
3
-
4
-
5
- def binary_dice_coefficient(mask1: np.ndarray, mask2: np.ndarray) -> float:
6
- """Calculate the dice coefficient between two binary masks.
7
-
8
- Args:
9
- mask1 (np.ndarray): A binary mask.
10
- mask2 (np.ndarray): A binary mask.
11
-
12
- Returns:
13
- float: The dice coefficient between the two masks.
14
-
15
- """
16
- # Convert the masks to binary.
17
- mask1 = mask1 > 0
18
- mask2 = mask2 > 0
19
-
20
- # Calculate dice.
21
- intersection = np.sum(mask1 * mask2)
22
-
23
- sum_masks = np.sum(mask1) + np.sum(mask2)
24
-
25
- if sum_masks == 0:
26
- return 1.0 # Both masks are empty
27
-
28
- return 2.0 * intersection / sum_masks
@@ -1,18 +0,0 @@
1
- FROM python:3.11-slim-buster
2
-
3
- ENV PYTHONUNBUFFERED True
4
-
5
- RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
6
-
7
- WORKDIR /app
8
-
9
- COPY requirements.txt /app
10
-
11
- RUN pip install --upgrade pip
12
-
13
- RUN python -m pip install pymongo==4.9.1
14
-
15
- RUN pip install --no-cache-dir -r requirements.txt
16
-
17
- COPY dsa_helpers-0.4.dev1-py3-none-any.whl /app
18
- RUN pip install dsa_helpers-0.4.dev1-py3-none-any.whl
@@ -1,55 +0,0 @@
1
- from dash import html, Dash, callback, Output, Input, State, no_update
2
- import dash_bootstrap_components as dbc
3
- from dsa_helpers.dash.header import get_header
4
- from os import getenv
5
- from dash_ag_grid import AgGrid
6
-
7
- table = AgGrid(
8
- id="table",
9
- columnDefs=[],
10
- rowData=[],
11
- )
12
-
13
- app = Dash(
14
- __name__,
15
- external_stylesheets=[
16
- dbc.themes.BOOTSTRAP,
17
- ],
18
- title="Test Application",
19
- )
20
-
21
- app.layout = html.Div(
22
- [
23
- get_header(
24
- getenv("DSA_API_URL"),
25
- title="Test Application",
26
- store_id="user-store",
27
- ),
28
- dbc.Row(
29
- [dbc.Col(dbc.Button("Get items", id="get-item-btn"), width="auto")],
30
- justify="start",
31
- ),
32
- table
33
- ]
34
- )
35
-
36
-
37
- @callback(
38
- [
39
- Output("table", "columnDefs"),
40
- Output("table", "rowData"),
41
- ],
42
- Input("get-item-btn", "n_clicks"),
43
- prevent_initial_call=True,
44
- )
45
- def get_items(n_clicks):
46
- """Get the items."""
47
-
48
-
49
-
50
- if __name__ == "__main__":
51
- app.run(
52
- host="0.0.0.0",
53
- port=8060,
54
- debug=True,
55
- )
@@ -1,31 +0,0 @@
1
- volumes:
2
- mongodb-data-volume:
3
-
4
- services:
5
- mongodb:
6
- image: mongo:7.0.6-jammy
7
- restart: always
8
- platform: linux/amd64
9
- container_name: mongodb
10
- volumes:
11
- - mongodb-data-volume:/data/db
12
- ports:
13
- - 27017:27017
14
- env_file: .env
15
- command: [ "--quiet", "--maxConns", "1000" ]
16
- logging:
17
- options:
18
- max-size: "10M"
19
- max-file: "5"
20
-
21
- dash:
22
- build: app/
23
- platform: linux/amd64
24
- volumes:
25
- - ./app:/app
26
- ports:
27
- - 8060:8060
28
- env_file: .env
29
- command: python app.py
30
- depends_on:
31
- - mongodb