зеркало из https://github.com/microsoft/torchgeo.git
Bump ruff from 0.4.4 to 0.4.5 in /requirements (#2080)
* Bump ruff from 0.4.4 to 0.4.5 in /requirements Bumps [ruff](https://github.com/astral-sh/ruff) from 0.4.4 to 0.4.5. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ruff/compare/v0.4.4...v0.4.5) --- updated-dependencies: - dependency-name: ruff dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * min version of numpy now supports type hints * pre-commit: update ruff --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com>
This commit is contained in:
Родитель
2aecee9c7a
Коммит
5cfbd6512d
|
@ -1,6 +1,6 @@
|
|||
repos:
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.3.7
|
||||
rev: v0.4.5
|
||||
hooks:
|
||||
- id: ruff
|
||||
types_or:
|
||||
|
|
|
@ -29,7 +29,7 @@ def retrieve_mask_chip(
|
|||
mask array
|
||||
"""
|
||||
out_shape = (1, *img_src.shape)
|
||||
mask_chip: 'np.typing.NDArray[np.uint8]' = mask_src.read(
|
||||
mask_chip: np.typing.NDArray[np.uint8] = mask_src.read(
|
||||
out_shape=out_shape, window=from_bounds(*img_src.bounds, mask_src.transform)
|
||||
)
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# style
|
||||
mypy==1.10.0
|
||||
ruff==0.4.4
|
||||
ruff==0.4.5
|
||||
|
|
|
@ -561,7 +561,7 @@ def test_nonexisting_directory(tmp_path: Path) -> None:
|
|||
|
||||
|
||||
def test_percentile_normalization() -> None:
|
||||
img: 'np.typing.NDArray[np.int_]' = np.array([[1, 2], [98, 100]])
|
||||
img: np.typing.NDArray[np.int_] = np.array([[1, 2], [98, 100]])
|
||||
|
||||
img = percentile_normalization(img, 2, 98)
|
||||
assert img.min() == 0
|
||||
|
@ -573,7 +573,7 @@ def test_percentile_normalization() -> None:
|
|||
[np.uint8, np.uint16, np.uint32, np.int8, np.int16, np.int32, np.int64],
|
||||
)
|
||||
def test_array_to_tensor(array_dtype: 'np.typing.DTypeLike') -> None:
|
||||
array: 'np.typing.NDArray[Any]' = np.zeros((2,), dtype=array_dtype)
|
||||
array: np.typing.NDArray[Any] = np.zeros((2,), dtype=array_dtype)
|
||||
array[0] = np.iinfo(array.dtype).min
|
||||
array[1] = np.iinfo(array.dtype).max
|
||||
tensor = array_to_tensor(array)
|
||||
|
|
|
@ -179,7 +179,7 @@ class ADVANCE(NonGeoDataset):
|
|||
the image
|
||||
"""
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
|
|
@ -403,7 +403,7 @@ class BigEarthNet(NonGeoDataset):
|
|||
resampling=Resampling.bilinear,
|
||||
)
|
||||
images.append(array)
|
||||
arrays: 'np.typing.NDArray[np.int_]' = np.stack(images, axis=0)
|
||||
arrays: np.typing.NDArray[np.int_] = np.stack(images, axis=0)
|
||||
tensor = torch.from_numpy(arrays).float()
|
||||
return tensor
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ class BioMassters(NonGeoDataset):
|
|||
target mask
|
||||
"""
|
||||
with rasterio.open(os.path.join(self.root, 'train_agbm', filename), 'r') as src:
|
||||
arr: 'np.typing.NDArray[np.float_]' = src.read()
|
||||
arr: np.typing.NDArray[np.float_] = src.read()
|
||||
|
||||
target = torch.from_numpy(arr).float()
|
||||
return target
|
||||
|
|
|
@ -183,7 +183,7 @@ class CloudCoverDetection(NonGeoDataset):
|
|||
with rasterio.open(path) as image_data:
|
||||
image_array = image_data.read(1).astype(np.int32)
|
||||
images.append(image_array)
|
||||
image_stack: 'np.typing.NDArray[np.int_]' = np.stack(images, axis=0)
|
||||
image_stack: np.typing.NDArray[np.int_] = np.stack(images, axis=0)
|
||||
image_tensor = torch.from_numpy(image_stack)
|
||||
return image_tensor
|
||||
|
||||
|
@ -200,7 +200,7 @@ class CloudCoverDetection(NonGeoDataset):
|
|||
with rasterio.open(label_asset_path) as target_data:
|
||||
target_img = target_data.read(1).astype(np.int32)
|
||||
|
||||
target_array: 'np.typing.NDArray[np.int_]' = np.array(target_img)
|
||||
target_array: np.typing.NDArray[np.int_] = np.array(target_img)
|
||||
target_tensor = torch.from_numpy(target_array)
|
||||
return target_tensor
|
||||
|
||||
|
|
|
@ -145,7 +145,7 @@ class COWC(NonGeoDataset, abc.ABC):
|
|||
"""
|
||||
filename = os.path.join(self.root, self.images[index])
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img)
|
||||
array: np.typing.NDArray[np.int_] = np.array(img)
|
||||
tensor = torch.from_numpy(array).float()
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
|
|
@ -235,7 +235,7 @@ class CV4AKenyaCropType(NonGeoDataset):
|
|||
)
|
||||
|
||||
with Image.open(os.path.join(directory, 'labels.tif')) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img)
|
||||
array: np.typing.NDArray[np.int_] = np.array(img)
|
||||
labels = torch.from_numpy(array)
|
||||
|
||||
with Image.open(os.path.join(directory, 'field_ids.tif')) as img:
|
||||
|
@ -332,7 +332,7 @@ class CV4AKenyaCropType(NonGeoDataset):
|
|||
f'{band_name}.tif',
|
||||
)
|
||||
with Image.open(filepath) as band_img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(band_img)
|
||||
array: np.typing.NDArray[np.int_] = np.array(band_img)
|
||||
img[band_index] = torch.from_numpy(array)
|
||||
|
||||
return img
|
||||
|
|
|
@ -159,7 +159,7 @@ class TropicalCyclone(NonGeoDataset):
|
|||
except AttributeError:
|
||||
resample = Image.BILINEAR # type: ignore[attr-defined]
|
||||
img = img.resize(size=(self.size, self.size), resample=resample)
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor = torch.from_numpy(array)
|
||||
tensor = tensor.permute((2, 0, 1)).float()
|
||||
return tensor
|
||||
|
|
|
@ -184,7 +184,7 @@ class DeepGlobeLandCover(NonGeoDataset):
|
|||
path = self.image_fns[index]
|
||||
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img)
|
||||
array: np.typing.NDArray[np.int_] = np.array(img)
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1)).to(torch.float32)
|
||||
|
@ -201,7 +201,7 @@ class DeepGlobeLandCover(NonGeoDataset):
|
|||
"""
|
||||
path = self.mask_fns[index]
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.uint8]' = np.array(img)
|
||||
array: np.typing.NDArray[np.uint8] = np.array(img)
|
||||
array = rgb_to_mask(array, self.colormap)
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
|
|
|
@ -235,7 +235,7 @@ class DFC2022(NonGeoDataset):
|
|||
the image
|
||||
"""
|
||||
with rasterio.open(path) as f:
|
||||
array: 'np.typing.NDArray[np.float_]' = f.read(
|
||||
array: np.typing.NDArray[np.float_] = f.read(
|
||||
out_shape=shape, out_dtype='float32', resampling=Resampling.bilinear
|
||||
)
|
||||
tensor = torch.from_numpy(array)
|
||||
|
@ -251,7 +251,7 @@ class DFC2022(NonGeoDataset):
|
|||
the target mask
|
||||
"""
|
||||
with rasterio.open(path) as f:
|
||||
array: 'np.typing.NDArray[np.int_]' = f.read(
|
||||
array: np.typing.NDArray[np.int_] = f.read(
|
||||
indexes=1, out_dtype='int32', resampling=Resampling.bilinear
|
||||
)
|
||||
tensor = torch.from_numpy(array)
|
||||
|
|
|
@ -204,7 +204,7 @@ class ETCI2021(NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor = torch.from_numpy(array).float()
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
@ -221,7 +221,7 @@ class ETCI2021(NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
|
||||
tensor = torch.from_numpy(array)
|
||||
tensor = torch.clamp(tensor, min=0, max=1)
|
||||
tensor = tensor.to(torch.long)
|
||||
|
|
|
@ -246,7 +246,7 @@ class EuroCrops(VectorDataset):
|
|||
def apply_cmap(arr: 'np.typing.NDArray[Any]') -> 'np.typing.NDArray[np.float_]':
|
||||
# Color 0 as black, while applying default color map for the class indices.
|
||||
cmap = plt.get_cmap('viridis')
|
||||
im: 'np.typing.NDArray[np.float_]' = cmap(arr / len(self.class_map))
|
||||
im: np.typing.NDArray[np.float_] = cmap(arr / len(self.class_map))
|
||||
im[arr == 0] = 0
|
||||
return im
|
||||
|
||||
|
|
|
@ -308,7 +308,7 @@ class FAIR1M(NonGeoDataset):
|
|||
the image
|
||||
"""
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
|
|
@ -197,7 +197,7 @@ class ForestDamage(NonGeoDataset):
|
|||
the image
|
||||
"""
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor: Tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
|
|
@ -904,7 +904,7 @@ class NonGeoClassificationDataset(NonGeoDataset, ImageFolder): # type: ignore[m
|
|||
the image and class label
|
||||
"""
|
||||
img, label = ImageFolder.__getitem__(self, index)
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img)
|
||||
array: np.typing.NDArray[np.int_] = np.array(img)
|
||||
tensor = torch.from_numpy(array).float()
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
|
|
@ -189,7 +189,7 @@ class GID15(NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1)).float()
|
||||
|
@ -206,7 +206,7 @@ class GID15(NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
|
||||
tensor = torch.from_numpy(array)
|
||||
tensor = tensor.to(torch.long)
|
||||
return tensor
|
||||
|
|
|
@ -265,7 +265,7 @@ class IDTReeS(NonGeoDataset):
|
|||
"""
|
||||
laspy = lazy_import('laspy')
|
||||
las = laspy.read(path)
|
||||
array: 'np.typing.NDArray[np.int_]' = np.stack([las.x, las.y, las.z], axis=0)
|
||||
array: np.typing.NDArray[np.int_] = np.stack([las.x, las.y, las.z], axis=0)
|
||||
tensor = torch.from_numpy(array)
|
||||
return tensor
|
||||
|
||||
|
@ -570,7 +570,7 @@ class IDTReeS(NonGeoDataset):
|
|||
path = self.images[index]
|
||||
path = path.replace('RGB', 'LAS').replace('.tif', '.las')
|
||||
las = laspy.read(path)
|
||||
points: 'np.typing.NDArray[np.int_]' = np.stack(
|
||||
points: np.typing.NDArray[np.int_] = np.stack(
|
||||
[las.x, las.y, las.z], axis=0
|
||||
).transpose((1, 0))
|
||||
point_cloud = pyvista.PolyData(points)
|
||||
|
|
|
@ -360,7 +360,7 @@ class LandCoverAI(LandCoverAIBase, NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(self.root, 'output', id_ + '.jpg')
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img)
|
||||
array: np.typing.NDArray[np.int_] = np.array(img)
|
||||
tensor = torch.from_numpy(array).float()
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
@ -378,7 +378,7 @@ class LandCoverAI(LandCoverAIBase, NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(self.root, 'output', id_ + '_m.png')
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
|
||||
tensor = torch.from_numpy(array).long()
|
||||
return tensor
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ class LEVIRCDBase(NonGeoDataset, abc.ABC):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor = torch.from_numpy(array).float()
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
@ -122,7 +122,7 @@ class LEVIRCDBase(NonGeoDataset, abc.ABC):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
|
||||
tensor = torch.from_numpy(array)
|
||||
tensor = torch.clamp(tensor, min=0, max=1)
|
||||
tensor = tensor.to(torch.long)
|
||||
|
|
|
@ -208,7 +208,7 @@ class LoveDA(NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor = torch.from_numpy(array).float()
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
@ -225,7 +225,7 @@ class LoveDA(NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
|
||||
tensor = torch.from_numpy(array)
|
||||
tensor = tensor.to(torch.long)
|
||||
return tensor
|
||||
|
|
|
@ -217,7 +217,7 @@ class MapInWild(NonGeoDataset):
|
|||
"""
|
||||
with rasterio.open(os.path.join(self.root, source, f'{filename}.tif')) as f:
|
||||
raw_array = f.read()
|
||||
array: 'np.typing.NDArray[np.int_]' = np.stack(raw_array, axis=0)
|
||||
array: np.typing.NDArray[np.int_] = np.stack(raw_array, axis=0)
|
||||
if array.dtype == np.uint16:
|
||||
array = array.astype(np.int32)
|
||||
tensor = torch.from_numpy(array).float()
|
||||
|
|
|
@ -305,7 +305,7 @@ class MillionAID(NonGeoDataset):
|
|||
the image
|
||||
"""
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor: Tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
|
|
@ -216,11 +216,11 @@ class OSCD(NonGeoDataset):
|
|||
Returns:
|
||||
the image
|
||||
"""
|
||||
images: list['np.typing.NDArray[np.int_]'] = []
|
||||
images: list[np.typing.NDArray[np.int_]] = []
|
||||
for path in paths:
|
||||
with Image.open(path) as img:
|
||||
images.append(np.array(img))
|
||||
array: 'np.typing.NDArray[np.int_]' = np.stack(images, axis=0).astype(np.int_)
|
||||
array: np.typing.NDArray[np.int_] = np.stack(images, axis=0).astype(np.int_)
|
||||
tensor = torch.from_numpy(array).float()
|
||||
return tensor
|
||||
|
||||
|
@ -235,7 +235,7 @@ class OSCD(NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
|
||||
tensor = torch.from_numpy(array)
|
||||
tensor = torch.clamp(tensor, min=0, max=1)
|
||||
tensor = tensor.to(torch.long)
|
||||
|
@ -314,7 +314,7 @@ class OSCD(NonGeoDataset):
|
|||
rgb_img = (np.clip((rgb_img - per02) / (per98 - per02), 0, 1) * 255).astype(
|
||||
np.uint8
|
||||
)
|
||||
array: 'np.typing.NDArray[np.uint8]' = draw_semantic_segmentation_masks(
|
||||
array: np.typing.NDArray[np.uint8] = draw_semantic_segmentation_masks(
|
||||
torch.from_numpy(rgb_img),
|
||||
sample['mask'],
|
||||
alpha=alpha,
|
||||
|
|
|
@ -206,7 +206,7 @@ class Potsdam2D(NonGeoDataset):
|
|||
"""
|
||||
path = self.files[index]['mask']
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.uint8]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.uint8] = np.array(img.convert('RGB'))
|
||||
array = rgb_to_mask(array, self.colormap)
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
|
|
|
@ -147,7 +147,7 @@ class ReforesTree(NonGeoDataset):
|
|||
the image
|
||||
"""
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.uint8]' = np.array(img)
|
||||
array: np.typing.NDArray[np.uint8] = np.array(img)
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
|
|
@ -230,7 +230,7 @@ class So2Sat(NonGeoDataset):
|
|||
assert split in self.filenames_by_version[version]
|
||||
|
||||
self._validate_bands(bands)
|
||||
self.s1_band_indices: 'np.typing.NDArray[np.int_]' = np.array(
|
||||
self.s1_band_indices: np.typing.NDArray[np.int_] = np.array(
|
||||
[
|
||||
self.all_s1_band_names.index(b)
|
||||
for b in bands
|
||||
|
@ -240,7 +240,7 @@ class So2Sat(NonGeoDataset):
|
|||
|
||||
self.s1_band_names = [self.all_s1_band_names[i] for i in self.s1_band_indices]
|
||||
|
||||
self.s2_band_indices: 'np.typing.NDArray[np.int_]' = np.array(
|
||||
self.s2_band_indices: np.typing.NDArray[np.int_] = np.array(
|
||||
[
|
||||
self.all_s2_band_names.index(b)
|
||||
for b in bands
|
||||
|
|
|
@ -686,7 +686,7 @@ class SpaceNet3(SpaceNet):
|
|||
max_speed_bin = 65
|
||||
speed_arr_bin = np.arange(min_speed_bin, max_speed_bin + 1)
|
||||
bin_size_mph = 10.0
|
||||
speed_cls_arr: 'np.typing.NDArray[np.int_]' = np.array(
|
||||
speed_cls_arr: np.typing.NDArray[np.int_] = np.array(
|
||||
[math.ceil(s / bin_size_mph) for s in speed_arr_bin]
|
||||
)
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ class USAVars(NonGeoDataset):
|
|||
the image
|
||||
"""
|
||||
with rasterio.open(path) as f:
|
||||
array: 'np.typing.NDArray[np.int_]' = f.read()
|
||||
array: np.typing.NDArray[np.int_] = f.read()
|
||||
tensor = torch.from_numpy(array).float()
|
||||
return tensor
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ class Vaihingen2D(NonGeoDataset):
|
|||
"""
|
||||
path = self.files[index]['image']
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1)).float()
|
||||
|
@ -207,7 +207,7 @@ class Vaihingen2D(NonGeoDataset):
|
|||
"""
|
||||
path = self.files[index]['mask']
|
||||
with Image.open(path) as img:
|
||||
array: 'np.typing.NDArray[np.uint8]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.uint8] = np.array(img.convert('RGB'))
|
||||
array = rgb_to_mask(array, self.colormap)
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
|
|
|
@ -285,7 +285,7 @@ class VHR10(NonGeoDataset):
|
|||
f'{id_:03d}.jpg',
|
||||
)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img)
|
||||
array: np.typing.NDArray[np.int_] = np.array(img)
|
||||
tensor = torch.from_numpy(array)
|
||||
tensor = tensor.float()
|
||||
# Convert from HxWxC to CxHxW
|
||||
|
|
|
@ -163,7 +163,7 @@ class XView2(NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
|
||||
tensor = torch.from_numpy(array)
|
||||
# Convert from HxWxC to CxHxW
|
||||
tensor = tensor.permute((2, 0, 1))
|
||||
|
@ -180,7 +180,7 @@ class XView2(NonGeoDataset):
|
|||
"""
|
||||
filename = os.path.join(path)
|
||||
with Image.open(filename) as img:
|
||||
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
|
||||
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
|
||||
tensor = torch.from_numpy(array)
|
||||
tensor = tensor.to(torch.long)
|
||||
return tensor
|
||||
|
|
|
@ -165,7 +165,7 @@ class RCF(Module):
|
|||
sqrt_zca_eigs = np.sqrt(E)
|
||||
inv_sqrt_zca_eigs = np.diag(np.power(sqrt_zca_eigs, -1))
|
||||
global_ZCA = V.dot(inv_sqrt_zca_eigs).dot(V.T)
|
||||
patches_normalized: 'np.typing.NDArray[np.float32]' = (
|
||||
patches_normalized: np.typing.NDArray[np.float32] = (
|
||||
(patches).dot(global_ZCA).dot(global_ZCA.T)
|
||||
)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче