Add Open CV back to workflow
Browse filesBasic Numpy array may not be what datasets.Image expects.
- pest-management-opendata.py +18 -16
- requirements.txt +1 -0
pest-management-opendata.py
CHANGED
@@ -4,6 +4,7 @@ from pathlib import Path
|
|
4 |
from dataclasses import dataclass, asdict
|
5 |
from urllib.parse import urlparse, urlunparse
|
6 |
|
|
|
7 |
import boto3
|
8 |
import numpy as np
|
9 |
import pandas as pd
|
@@ -85,6 +86,7 @@ class SplitManager:
|
|
85 |
#
|
86 |
#
|
87 |
class ExampleManager:
|
|
|
88 |
# _Pest = cl.namedtuple('_Pest', 'label, geometry')
|
89 |
# _Feature = cl.namedtuple('_Feature', 'image, pests')
|
90 |
|
@@ -108,8 +110,20 @@ class ExampleManager:
|
|
108 |
'geometry': geometry.wkb,
|
109 |
}
|
110 |
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
path = Path(url.path)
|
114 |
if path.is_absolute():
|
115 |
(*_, root) = path.parents
|
@@ -122,21 +136,9 @@ class ExampleManager:
|
|
122 |
.get()
|
123 |
.get('Body')
|
124 |
.read())
|
|
|
125 |
|
126 |
-
return
|
127 |
-
|
128 |
-
def __init__(self, payload):
|
129 |
-
self.payload = payload
|
130 |
-
|
131 |
-
def __iter__(self):
|
132 |
-
df = self.payload.to_frame()
|
133 |
-
for (i, g) in df.groupby('url', sort=False):
|
134 |
-
value = {
|
135 |
-
'image': self.load(urlparse(i)),
|
136 |
-
'pests': list(self.pests(g)),
|
137 |
-
}
|
138 |
-
|
139 |
-
yield (i, value)
|
140 |
|
141 |
#
|
142 |
#
|
|
|
4 |
from dataclasses import dataclass, asdict
|
5 |
from urllib.parse import urlparse, urlunparse
|
6 |
|
7 |
+
import cv2
|
8 |
import boto3
|
9 |
import numpy as np
|
10 |
import pandas as pd
|
|
|
86 |
#
|
87 |
#
|
88 |
class ExampleManager:
|
89 |
+
_decode_flags = cv2.IMREAD_COLOR | cv2.IMREAD_IGNORE_ORIENTATION
|
90 |
# _Pest = cl.namedtuple('_Pest', 'label, geometry')
|
91 |
# _Feature = cl.namedtuple('_Feature', 'image, pests')
|
92 |
|
|
|
110 |
'geometry': geometry.wkb,
|
111 |
}
|
112 |
|
113 |
+
def __init__(self, payload):
|
114 |
+
self.payload = payload
|
115 |
+
|
116 |
+
def __iter__(self):
|
117 |
+
df = self.payload.to_frame()
|
118 |
+
for (i, g) in df.groupby('url', sort=False):
|
119 |
+
value = {
|
120 |
+
'image': self.load(urlparse(i)),
|
121 |
+
'pests': list(self.pests(g)),
|
122 |
+
}
|
123 |
+
|
124 |
+
yield (i, value)
|
125 |
+
|
126 |
+
def load(self, url):
|
127 |
path = Path(url.path)
|
128 |
if path.is_absolute():
|
129 |
(*_, root) = path.parents
|
|
|
136 |
.get()
|
137 |
.get('Body')
|
138 |
.read())
|
139 |
+
image = np.asarray(bytearray(data))
|
140 |
|
141 |
+
return cv2.imdecode(image, self._decode_flags)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
#
|
144 |
#
|
requirements.txt
CHANGED
@@ -2,5 +2,6 @@ awswrangler
|
|
2 |
boto3
|
3 |
datasets
|
4 |
numpy
|
|
|
5 |
pandas
|
6 |
shapely
|
|
|
2 |
boto3
|
3 |
datasets
|
4 |
numpy
|
5 |
+
opencv-python
|
6 |
pandas
|
7 |
shapely
|