Skip to content

Commit aaf00b0

Browse files
authored
Remove fsspec, s3fs and make the default loader and abstract interface (#345)
* Remove fsspec, s3fs and make the default loader and abstract interface * Update lockfile --no-update * Remove lock file * Removing 3.10 from poetry install matrix again * Bump version
1 parent 2d03c54 commit aaf00b0

File tree

8 files changed

+34
-3976
lines changed

8 files changed

+34
-3976
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ workflows:
165165
- test_poetry_installation:
166166
matrix:
167167
parameters:
168-
python_version: ['3.6', '3.7', '3.8', '3.9'] #, '3.10'] Haven't gotten the 3.10 poetry install test to work
168+
python_version: ['3.6', '3.7', '3.8', '3.9'] #, '3.10'] Need to work out a solution to support dev on 3.10
169169
context: Nucleus
170170
- test_client_installation:
171171
matrix:

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.14.15](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.15) - 2022-08-11
9+
10+
### Removed
11+
- Removed s3fs, fsspec dependencies for simpler installation in various environments
12+
813
## [0.14.14](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.14) - 2022-08-11
914

1015
### Added

nucleus/metrics/segmentation_loader.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1+
import abc
12
from typing import Dict
23

34
import numpy as np
4-
from PIL import Image
55

6-
try:
7-
import fsspec
8-
except (ModuleNotFoundError, OSError):
9-
from ..package_not_installed import PackageNotInstalled
106

11-
fsspec = PackageNotInstalled
7+
class SegmentationMaskLoader(abc.ABC):
8+
@abc.abstractmethod
9+
def fetch(self, url: str) -> np.ndarray:
10+
pass
1211

1312

14-
class SegmentationMaskLoader:
15-
def __init__(self, fs: fsspec):
16-
self.fs = fs
17-
18-
def fetch(self, url: str):
19-
with self.fs.open(url) as fh:
20-
img = Image.open(fh)
21-
return np.asarray(img)
13+
class DummyLoader(SegmentationMaskLoader):
14+
def fetch(self, url: str) -> np.ndarray:
15+
raise NotImplementedError(
16+
"This dummy loader has to be replaced with an actual implementation of an image loader"
17+
)
2218

2319

24-
class InMemoryLoader:
20+
class InMemoryLoader(SegmentationMaskLoader):
2521
"""We use this loader in the tests, this allows us to serve images from memory instead of fetching
2622
from a filesystem.
2723
"""

nucleus/metrics/segmentation_metrics.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from nucleus.prediction import PredictionList, SegmentationPrediction
1010

1111
from .base import Metric, ScalarResult
12-
from .segmentation_loader import SegmentationMaskLoader
12+
from .segmentation_loader import DummyLoader, SegmentationMaskLoader
1313
from .segmentation_utils import (
1414
FALSE_POSITIVES,
1515
convert_to_instance_seg_confusion,
@@ -18,14 +18,6 @@
1818
setup_iou_thresholds,
1919
)
2020

21-
try:
22-
from s3fs import S3FileSystem
23-
except (ModuleNotFoundError, OSError):
24-
from ..package_not_installed import PackageNotInstalled
25-
26-
S3FileSystem = PackageNotInstalled
27-
28-
2921
# pylint: disable=useless-super-delegation
3022

3123

@@ -64,7 +56,7 @@ def __init__(
6456
"""
6557
# TODO -> add custom filtering to Segmentation(Annotation|Prediction).annotations.(metadata|label)
6658
super().__init__(annotation_filters, prediction_filters)
67-
self.loader = SegmentationMaskLoader(S3FileSystem(anon=False))
59+
self.loader: SegmentationMaskLoader = DummyLoader()
6860
self.iou_threshold = iou_threshold
6961

7062
def call_metric(

nucleus/metrics/segmentation_to_poly_metrics.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,24 @@
2020
)
2121
from nucleus.prediction import PredictionList
2222

23-
from .segmentation_loader import InMemoryLoader, SegmentationMaskLoader
24-
from .segmentation_metrics import (
25-
SegmentationIOU,
26-
SegmentationMAP,
27-
SegmentationPrecision,
28-
SegmentationRecall,
29-
)
30-
31-
try:
32-
from s3fs import S3FileSystem
33-
except (ModuleNotFoundError, OSError):
34-
from ..package_not_installed import PackageNotInstalled
35-
36-
S3FileSystem = PackageNotInstalled
37-
3823
from .base import Metric, ScalarResult
3924
from .polygon_metrics import (
4025
PolygonAveragePrecision,
4126
PolygonIOU,
4227
PolygonPrecision,
4328
PolygonRecall,
4429
)
30+
from .segmentation_loader import (
31+
DummyLoader,
32+
InMemoryLoader,
33+
SegmentationMaskLoader,
34+
)
35+
from .segmentation_metrics import (
36+
SegmentationIOU,
37+
SegmentationMAP,
38+
SegmentationPrecision,
39+
SegmentationRecall,
40+
)
4541

4642

4743
class SegToPolyMode(str, Enum):
@@ -93,7 +89,7 @@ def __init__(
9389
self.enforce_label_match = enforce_label_match
9490
assert 0 <= confidence_threshold <= 1
9591
self.confidence_threshold = confidence_threshold
96-
self.loader = SegmentationMaskLoader(S3FileSystem(anon=False))
92+
self.loader: SegmentationMaskLoader = DummyLoader()
9793
self.mode = mode
9894

9995
def call_metric(

nucleus/metrics/segmentation_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def non_max_suppress_confusion(confusion: np.ndarray, iou_threshold):
166166

167167

168168
def rasterize_polygons_to_segmentation_mask(
169-
annotations: Sequence[BoxOrPolygonAnnotation], shape: Tuple[int, int]
169+
annotations: Sequence[BoxOrPolygonAnnotation], shape: Tuple
170170
) -> Tuple[np.ndarray, List[Segment]]:
171171
polys = [polygon_annotation_to_shape(a) for a in annotations]
172172
segments = [

0 commit comments

Comments
 (0)