@@ -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
130126def 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" ]
0 commit comments