Skip to content

Commit 8a6009a

Browse files
committed
Update search_images
1 parent 4a1eca8 commit 8a6009a

3 files changed

Lines changed: 9 additions & 14 deletions

File tree

abraia/training/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .dataset import list_datasets, load_dataset, search_images, list_models, download_file
1111

1212

13+
#TODO: Remove on next release
1314
def load_tasks(task):
1415
if task:
1516
tasks = ['classify', 'detect', 'segment']

abraia/training/dataset.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def search_google(query):
8585
yield link
8686

8787

88-
def download(query, limit=100, save_output='dataset', verbose=True, callback=None):
88+
def search_images(query, limit=100, save_output='dataset', callback=None):
89+
"""Search and download images from Google and Bing."""
8990
seen = set()
9091
download_count = 0
9192
os.makedirs(save_output, exist_ok=True)
@@ -100,23 +101,18 @@ def download(query, limit=100, save_output='dataset', verbose=True, callback=Non
100101
try:
101102
save_image_file(link, save_output)
102103
download_count += 1
103-
if verbose:
104-
print(f"[%] Downloaded Image #{download_count} from {link}")
105104
if callback:
106-
callback({'current': download_count, 'total': limit})
107-
except Exception as e:
108-
print(f"[!] Error getting {link}: {e}")
105+
callback({'current': download_count, 'total': limit, 'link': link})
106+
else:
107+
print(f"[%] Downloaded Image #{download_count} from {link}")
108+
except Exception:
109+
print(f"[!] Error Image #{download_count} from {link}")
109110
else:
110111
break
111112
except StopIteration:
112113
ends[id] = True
113114
if set(ends) == {True}:
114115
break
115-
116-
117-
def search_images(query, limit=100, save_output='dataset', verbose=True, callback=None):
118-
"""Search and download images from Google and Bing."""
119-
download(query, limit=limit, save_output=save_output, verbose=verbose, callback=callback)
120116
return list_dir(save_output)
121117

122118

@@ -129,14 +125,12 @@ def download_file(path, folder):
129125

130126
def detect_dino(img, classes, threshold=0.3, pipe=None):
131127
"""Detect objects in an image using Grounding Dino."""
132-
133128
classes = [label.lower().strip() for label in classes]
134129
labels = [f"{label}." if not label.endswith('.') else label for label in classes]
135130
if pipe is None:
136131
from transformers import pipeline
137132
pipe = pipeline(task="zero-shot-object-detection", model="IDEA-Research/grounding-dino-tiny")
138133
results = pipe(Image.fromarray(img), candidate_labels=labels, threshold=threshold)
139-
140134
objects = []
141135
for result in results:
142136
score = result["score"]

scripts/abraia

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def create(project, query, anonymize=False, upscale=0):
202202
dataset = load_dataset(project)
203203
files = []
204204
if query:
205-
files = search_images(query, limit=100, save_output=f"{project}/", verbose=True)
205+
files = search_images(query, limit=100, save_output=f"{project}/")
206206
if os.path.exists(project):
207207
files = process_dataset(project, anonymize=anonymize, upscale_threshold=upscale)
208208
process_map(upload_file, files, itertools.repeat(project + '/'), desc="Uploading images")

0 commit comments

Comments
 (0)