geoai-py 0.3.4__py2.py3-none-any.whl → 0.3.5__py2.py3-none-any.whl
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.
- geoai/__init__.py +1 -1
- geoai/extract.py +109 -87
- geoai/utils.py +2 -0
- {geoai_py-0.3.4.dist-info → geoai_py-0.3.5.dist-info}/METADATA +1 -1
- geoai_py-0.3.5.dist-info/RECORD +13 -0
- geoai_py-0.3.4.dist-info/RECORD +0 -13
- {geoai_py-0.3.4.dist-info → geoai_py-0.3.5.dist-info}/LICENSE +0 -0
- {geoai_py-0.3.4.dist-info → geoai_py-0.3.5.dist-info}/WHEEL +0 -0
- {geoai_py-0.3.4.dist-info → geoai_py-0.3.5.dist-info}/entry_points.txt +0 -0
- {geoai_py-0.3.4.dist-info → geoai_py-0.3.5.dist-info}/top_level.txt +0 -0
geoai/__init__.py
CHANGED
geoai/extract.py
CHANGED
|
@@ -1881,88 +1881,6 @@ class ObjectDetector:
|
|
|
1881
1881
|
plt.savefig(sample_output, dpi=300, bbox_inches="tight")
|
|
1882
1882
|
print(f"Sample visualization saved to {sample_output}")
|
|
1883
1883
|
|
|
1884
|
-
|
|
1885
|
-
class BuildingFootprintExtractor(ObjectDetector):
|
|
1886
|
-
"""
|
|
1887
|
-
Building footprint extraction using a pre-trained Mask R-CNN model.
|
|
1888
|
-
|
|
1889
|
-
This class extends the
|
|
1890
|
-
`ObjectDetector` class with additional methods for building footprint extraction."
|
|
1891
|
-
"""
|
|
1892
|
-
|
|
1893
|
-
def __init__(
|
|
1894
|
-
self,
|
|
1895
|
-
model_path="building_footprints_usa.pth",
|
|
1896
|
-
repo_id=None,
|
|
1897
|
-
model=None,
|
|
1898
|
-
device=None,
|
|
1899
|
-
):
|
|
1900
|
-
"""
|
|
1901
|
-
Initialize the object extractor.
|
|
1902
|
-
|
|
1903
|
-
Args:
|
|
1904
|
-
model_path: Path to the .pth model file.
|
|
1905
|
-
repo_id: Repo ID for loading models from the Hub.
|
|
1906
|
-
model: Custom model to use for inference.
|
|
1907
|
-
device: Device to use for inference ('cuda:0', 'cpu', etc.).
|
|
1908
|
-
"""
|
|
1909
|
-
super().__init__(
|
|
1910
|
-
model_path=model_path, repo_id=repo_id, model=model, device=device
|
|
1911
|
-
)
|
|
1912
|
-
|
|
1913
|
-
def regularize_buildings(
|
|
1914
|
-
self,
|
|
1915
|
-
gdf,
|
|
1916
|
-
min_area=10,
|
|
1917
|
-
angle_threshold=15,
|
|
1918
|
-
orthogonality_threshold=0.3,
|
|
1919
|
-
rectangularity_threshold=0.7,
|
|
1920
|
-
):
|
|
1921
|
-
"""
|
|
1922
|
-
Regularize building footprints to enforce right angles and rectangular shapes.
|
|
1923
|
-
|
|
1924
|
-
Args:
|
|
1925
|
-
gdf: GeoDataFrame with building footprints
|
|
1926
|
-
min_area: Minimum area in square units to keep a building
|
|
1927
|
-
angle_threshold: Maximum deviation from 90 degrees to consider an angle as orthogonal (degrees)
|
|
1928
|
-
orthogonality_threshold: Percentage of angles that must be orthogonal for a building to be regularized
|
|
1929
|
-
rectangularity_threshold: Minimum area ratio to building's oriented bounding box for rectangular simplification
|
|
1930
|
-
|
|
1931
|
-
Returns:
|
|
1932
|
-
GeoDataFrame with regularized building footprints
|
|
1933
|
-
"""
|
|
1934
|
-
return self.regularize_objects(
|
|
1935
|
-
gdf,
|
|
1936
|
-
min_area=min_area,
|
|
1937
|
-
angle_threshold=angle_threshold,
|
|
1938
|
-
orthogonality_threshold=orthogonality_threshold,
|
|
1939
|
-
rectangularity_threshold=rectangularity_threshold,
|
|
1940
|
-
)
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
class CarDetector(ObjectDetector):
|
|
1944
|
-
"""
|
|
1945
|
-
Car detection using a pre-trained Mask R-CNN model.
|
|
1946
|
-
|
|
1947
|
-
This class extends the `ObjectDetector` class with additional methods for car detection.
|
|
1948
|
-
"""
|
|
1949
|
-
|
|
1950
|
-
def __init__(
|
|
1951
|
-
self, model_path="car_detection_usa.pth", repo_id=None, model=None, device=None
|
|
1952
|
-
):
|
|
1953
|
-
"""
|
|
1954
|
-
Initialize the object extractor.
|
|
1955
|
-
|
|
1956
|
-
Args:
|
|
1957
|
-
model_path: Path to the .pth model file.
|
|
1958
|
-
repo_id: Repo ID for loading models from the Hub.
|
|
1959
|
-
model: Custom model to use for inference.
|
|
1960
|
-
device: Device to use for inference ('cuda:0', 'cpu', etc.).
|
|
1961
|
-
"""
|
|
1962
|
-
super().__init__(
|
|
1963
|
-
model_path=model_path, repo_id=repo_id, model=model, device=device
|
|
1964
|
-
)
|
|
1965
|
-
|
|
1966
1884
|
def generate_masks(
|
|
1967
1885
|
self,
|
|
1968
1886
|
raster_path,
|
|
@@ -1972,6 +1890,7 @@ class CarDetector(ObjectDetector):
|
|
|
1972
1890
|
overlap=0.25,
|
|
1973
1891
|
batch_size=4,
|
|
1974
1892
|
verbose=False,
|
|
1893
|
+
**kwargs,
|
|
1975
1894
|
):
|
|
1976
1895
|
"""
|
|
1977
1896
|
Save masks with confidence values as a multi-band GeoTIFF.
|
|
@@ -1994,6 +1913,8 @@ class CarDetector(ObjectDetector):
|
|
|
1994
1913
|
if mask_threshold is None:
|
|
1995
1914
|
mask_threshold = self.mask_threshold
|
|
1996
1915
|
|
|
1916
|
+
chip_size = kwargs.get("chip_size", self.chip_size)
|
|
1917
|
+
|
|
1997
1918
|
# Default output path
|
|
1998
1919
|
if output_path is None:
|
|
1999
1920
|
output_path = os.path.splitext(raster_path)[0] + "_masks_conf.tif"
|
|
@@ -2003,7 +1924,7 @@ class CarDetector(ObjectDetector):
|
|
|
2003
1924
|
# Create dataset with the specified overlap
|
|
2004
1925
|
dataset = CustomDataset(
|
|
2005
1926
|
raster_path=raster_path,
|
|
2006
|
-
chip_size=
|
|
1927
|
+
chip_size=chip_size,
|
|
2007
1928
|
overlap=overlap,
|
|
2008
1929
|
verbose=verbose,
|
|
2009
1930
|
)
|
|
@@ -2135,13 +2056,24 @@ class CarDetector(ObjectDetector):
|
|
|
2135
2056
|
print(f"Masks with confidence values saved to {output_path}")
|
|
2136
2057
|
return output_path
|
|
2137
2058
|
|
|
2138
|
-
def vectorize_masks(
|
|
2059
|
+
def vectorize_masks(
|
|
2060
|
+
self,
|
|
2061
|
+
masks_path,
|
|
2062
|
+
output_path=None,
|
|
2063
|
+
confidence_threshold=0.5,
|
|
2064
|
+
min_object_area=100,
|
|
2065
|
+
max_object_size=None,
|
|
2066
|
+
**kwargs,
|
|
2067
|
+
):
|
|
2139
2068
|
"""
|
|
2140
2069
|
Convert masks with confidence to vector polygons.
|
|
2141
2070
|
|
|
2142
2071
|
Args:
|
|
2143
|
-
masks_path: Path to masks GeoTIFF with confidence band
|
|
2144
|
-
output_path: Path for output GeoJSON
|
|
2072
|
+
masks_path: Path to masks GeoTIFF with confidence band.
|
|
2073
|
+
output_path: Path for output GeoJSON.
|
|
2074
|
+
confidence_threshold: Minimum confidence score (0.0-1.0). Default: 0.5
|
|
2075
|
+
min_object_area: Minimum area in pixels to keep an object. Default: 100
|
|
2076
|
+
max_object_size: Maximum area in pixels to keep an object. Default: None
|
|
2145
2077
|
**kwargs: Additional parameters
|
|
2146
2078
|
|
|
2147
2079
|
Returns:
|
|
@@ -2182,6 +2114,10 @@ class CarDetector(ObjectDetector):
|
|
|
2182
2114
|
else:
|
|
2183
2115
|
confidence = 0.0
|
|
2184
2116
|
|
|
2117
|
+
# Skip if confidence is below threshold
|
|
2118
|
+
if confidence < confidence_threshold:
|
|
2119
|
+
continue
|
|
2120
|
+
|
|
2185
2121
|
# Find contours
|
|
2186
2122
|
contours, _ = cv2.findContours(
|
|
2187
2123
|
component_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE
|
|
@@ -2190,9 +2126,13 @@ class CarDetector(ObjectDetector):
|
|
|
2190
2126
|
for contour in contours:
|
|
2191
2127
|
# Filter by size
|
|
2192
2128
|
area = cv2.contourArea(contour)
|
|
2193
|
-
if area <
|
|
2129
|
+
if area < min_object_area:
|
|
2194
2130
|
continue
|
|
2195
2131
|
|
|
2132
|
+
if max_object_size is not None:
|
|
2133
|
+
if area > max_object_size:
|
|
2134
|
+
continue
|
|
2135
|
+
|
|
2196
2136
|
# Get minimum area rectangle
|
|
2197
2137
|
rect = cv2.minAreaRect(contour)
|
|
2198
2138
|
box_points = cv2.boxPoints(rect)
|
|
@@ -2232,6 +2172,88 @@ class CarDetector(ObjectDetector):
|
|
|
2232
2172
|
return None
|
|
2233
2173
|
|
|
2234
2174
|
|
|
2175
|
+
class BuildingFootprintExtractor(ObjectDetector):
|
|
2176
|
+
"""
|
|
2177
|
+
Building footprint extraction using a pre-trained Mask R-CNN model.
|
|
2178
|
+
|
|
2179
|
+
This class extends the
|
|
2180
|
+
`ObjectDetector` class with additional methods for building footprint extraction."
|
|
2181
|
+
"""
|
|
2182
|
+
|
|
2183
|
+
def __init__(
|
|
2184
|
+
self,
|
|
2185
|
+
model_path="building_footprints_usa.pth",
|
|
2186
|
+
repo_id=None,
|
|
2187
|
+
model=None,
|
|
2188
|
+
device=None,
|
|
2189
|
+
):
|
|
2190
|
+
"""
|
|
2191
|
+
Initialize the object extractor.
|
|
2192
|
+
|
|
2193
|
+
Args:
|
|
2194
|
+
model_path: Path to the .pth model file.
|
|
2195
|
+
repo_id: Repo ID for loading models from the Hub.
|
|
2196
|
+
model: Custom model to use for inference.
|
|
2197
|
+
device: Device to use for inference ('cuda:0', 'cpu', etc.).
|
|
2198
|
+
"""
|
|
2199
|
+
super().__init__(
|
|
2200
|
+
model_path=model_path, repo_id=repo_id, model=model, device=device
|
|
2201
|
+
)
|
|
2202
|
+
|
|
2203
|
+
def regularize_buildings(
|
|
2204
|
+
self,
|
|
2205
|
+
gdf,
|
|
2206
|
+
min_area=10,
|
|
2207
|
+
angle_threshold=15,
|
|
2208
|
+
orthogonality_threshold=0.3,
|
|
2209
|
+
rectangularity_threshold=0.7,
|
|
2210
|
+
):
|
|
2211
|
+
"""
|
|
2212
|
+
Regularize building footprints to enforce right angles and rectangular shapes.
|
|
2213
|
+
|
|
2214
|
+
Args:
|
|
2215
|
+
gdf: GeoDataFrame with building footprints
|
|
2216
|
+
min_area: Minimum area in square units to keep a building
|
|
2217
|
+
angle_threshold: Maximum deviation from 90 degrees to consider an angle as orthogonal (degrees)
|
|
2218
|
+
orthogonality_threshold: Percentage of angles that must be orthogonal for a building to be regularized
|
|
2219
|
+
rectangularity_threshold: Minimum area ratio to building's oriented bounding box for rectangular simplification
|
|
2220
|
+
|
|
2221
|
+
Returns:
|
|
2222
|
+
GeoDataFrame with regularized building footprints
|
|
2223
|
+
"""
|
|
2224
|
+
return self.regularize_objects(
|
|
2225
|
+
gdf,
|
|
2226
|
+
min_area=min_area,
|
|
2227
|
+
angle_threshold=angle_threshold,
|
|
2228
|
+
orthogonality_threshold=orthogonality_threshold,
|
|
2229
|
+
rectangularity_threshold=rectangularity_threshold,
|
|
2230
|
+
)
|
|
2231
|
+
|
|
2232
|
+
|
|
2233
|
+
class CarDetector(ObjectDetector):
|
|
2234
|
+
"""
|
|
2235
|
+
Car detection using a pre-trained Mask R-CNN model.
|
|
2236
|
+
|
|
2237
|
+
This class extends the `ObjectDetector` class with additional methods for car detection.
|
|
2238
|
+
"""
|
|
2239
|
+
|
|
2240
|
+
def __init__(
|
|
2241
|
+
self, model_path="car_detection_usa.pth", repo_id=None, model=None, device=None
|
|
2242
|
+
):
|
|
2243
|
+
"""
|
|
2244
|
+
Initialize the object extractor.
|
|
2245
|
+
|
|
2246
|
+
Args:
|
|
2247
|
+
model_path: Path to the .pth model file.
|
|
2248
|
+
repo_id: Repo ID for loading models from the Hub.
|
|
2249
|
+
model: Custom model to use for inference.
|
|
2250
|
+
device: Device to use for inference ('cuda:0', 'cpu', etc.).
|
|
2251
|
+
"""
|
|
2252
|
+
super().__init__(
|
|
2253
|
+
model_path=model_path, repo_id=repo_id, model=model, device=device
|
|
2254
|
+
)
|
|
2255
|
+
|
|
2256
|
+
|
|
2235
2257
|
class ShipDetector(ObjectDetector):
|
|
2236
2258
|
"""
|
|
2237
2259
|
Ship detection using a pre-trained Mask R-CNN model.
|
geoai/utils.py
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
geoai/__init__.py,sha256=hZW6Fvb463-wq7iWzdssC41ErmU2G7st8ObOjmJfPd8,923
|
|
2
|
+
geoai/download.py,sha256=4GiDmLrp2wKslgfm507WeZrwOdYcMekgQXxWGbl5cBw,13094
|
|
3
|
+
geoai/extract.py,sha256=fyueuGWqL8vd9NqNyIWtxSFhbBSMUGCCkxySTR4xjy4,91467
|
|
4
|
+
geoai/geoai.py,sha256=7sbZ2LCZXaO0Io4Y7UH5tcQMFZH-sjYu_NENRKfyL5o,64
|
|
5
|
+
geoai/preprocess.py,sha256=ddUZUZ2fLNjzSIpXby7-MszM16GZt_gE9BMX4jdUZMw,119217
|
|
6
|
+
geoai/segmentation.py,sha256=Vcymnhwl_xikt4v9x8CYJq_vId9R1gB7-YzLfwg-F9M,11372
|
|
7
|
+
geoai/utils.py,sha256=cLBKrpXiYxFZWVR73ql0gHnt-78vSCvX7NPetvnTU4U,191690
|
|
8
|
+
geoai_py-0.3.5.dist-info/LICENSE,sha256=vN2L5U7cZ6ZkOHFmc8WiGlsogWsZc5dllMeNxnKVOZg,1070
|
|
9
|
+
geoai_py-0.3.5.dist-info/METADATA,sha256=HYWbzmYKYhO0FoIsrY0HGWRYGgpUKKL46Yixh_h0b2c,6059
|
|
10
|
+
geoai_py-0.3.5.dist-info/WHEEL,sha256=rF4EZyR2XVS6irmOHQIJx2SUqXLZKRMUrjsg8UwN-XQ,109
|
|
11
|
+
geoai_py-0.3.5.dist-info/entry_points.txt,sha256=uGp3Az3HURIsRHP9v-ys0hIbUuBBNUfXv6VbYHIXeg4,41
|
|
12
|
+
geoai_py-0.3.5.dist-info/top_level.txt,sha256=1YkCUWu-ii-0qIex7kbwAvfei-gos9ycyDyUCJPNWHY,6
|
|
13
|
+
geoai_py-0.3.5.dist-info/RECORD,,
|
geoai_py-0.3.4.dist-info/RECORD
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
geoai/__init__.py,sha256=cZwfZotU5b9Qc6MAxNA35RT3NtFtncGMM10SCvNzwgI,923
|
|
2
|
-
geoai/download.py,sha256=4GiDmLrp2wKslgfm507WeZrwOdYcMekgQXxWGbl5cBw,13094
|
|
3
|
-
geoai/extract.py,sha256=cATZ7J9PEFIOc96DCDnHcj-AjKI3MYyMxU1CWfhouAI,90745
|
|
4
|
-
geoai/geoai.py,sha256=7sbZ2LCZXaO0Io4Y7UH5tcQMFZH-sjYu_NENRKfyL5o,64
|
|
5
|
-
geoai/preprocess.py,sha256=ddUZUZ2fLNjzSIpXby7-MszM16GZt_gE9BMX4jdUZMw,119217
|
|
6
|
-
geoai/segmentation.py,sha256=Vcymnhwl_xikt4v9x8CYJq_vId9R1gB7-YzLfwg-F9M,11372
|
|
7
|
-
geoai/utils.py,sha256=5uFdWBgfw2_MTKsBObBXq3-nyY5TEQYPMJh4ap4eEag,191638
|
|
8
|
-
geoai_py-0.3.4.dist-info/LICENSE,sha256=vN2L5U7cZ6ZkOHFmc8WiGlsogWsZc5dllMeNxnKVOZg,1070
|
|
9
|
-
geoai_py-0.3.4.dist-info/METADATA,sha256=LU3GKiKaCcqQ_yBCgvYutzWO3EBgpvXtBJw4InficrU,6059
|
|
10
|
-
geoai_py-0.3.4.dist-info/WHEEL,sha256=rF4EZyR2XVS6irmOHQIJx2SUqXLZKRMUrjsg8UwN-XQ,109
|
|
11
|
-
geoai_py-0.3.4.dist-info/entry_points.txt,sha256=uGp3Az3HURIsRHP9v-ys0hIbUuBBNUfXv6VbYHIXeg4,41
|
|
12
|
-
geoai_py-0.3.4.dist-info/top_level.txt,sha256=1YkCUWu-ii-0qIex7kbwAvfei-gos9ycyDyUCJPNWHY,6
|
|
13
|
-
geoai_py-0.3.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|