@@ -511,8 +511,8 @@ def vggParams(self, vggParams):
511511 self .dirty_filters = True #for use in inherited classes, not needed for this explicitly
512512
513513
514- def generate (self , * args , pathonly = False , outflag = _cv2 .IMREAD_UNCHANGED , ** kwargs ):
515- '''(bool)-> ndarray,str, dict
514+ def generate (self , * args , pathonly = False , outflag = _cv2 .IMREAD_UNCHANGED , file_attr_match = None , ** kwargs ):
515+ '''(bool, int, dict )-> ndarray,str, dict
516516
517517 Uses the filters set in the VGGFilter and DigikamSearchParams
518518 to yield image regions to the caller.
@@ -522,6 +522,9 @@ def generate(self, *args, pathonly=False, outflag=_cv2.IMREAD_UNCHANGED, **kwarg
522522 outflag:
523523 cv2 flag for imread
524524 cv2.IMREAD_COLOR|cv2.IMREAD_GRAYSCALE|cv2.IMREAD_UNCHANGED
525+ file_attr_match:
526+ A dictionary, Only generate regions for file which match these attributes.
527+ e.g. file_attr_match = {'train'=1}
525528
526529 Returns [Yields]
527530 image region, imgpath, dictionary containing additional infornation
@@ -550,7 +553,7 @@ def generate(self, *args, pathonly=False, outflag=_cv2.IMREAD_UNCHANGED, **kwarg
550553 if not self .silent :
551554 print ('Opened regions file %s' % p )
552555
553- for Img in _vgg .imagesGenerator ():
556+ for Img in _vgg .imagesGenerator (file_attr_match = file_attr_match ):
554557
555558 if dk_image_list :
556559 if not Img .filepath in dk_image_list : # effectively applying a filter for the digikamlib conditions
@@ -593,7 +596,7 @@ def generate(self, *args, pathonly=False, outflag=_cv2.IMREAD_UNCHANGED, **kwarg
593596 if not self .silent :
594597 print ('Opened regions file %s' % p )
595598
596- for Img in _vgg .imagesGenerator ():
599+ for Img in _vgg .imagesGenerator (file_attr_match = file_attr_match ):
597600
598601 if dk_image_list :
599602 if not Img .filepath in dk_image_list : # effectively applying a filter for the digikamlib conditions
@@ -662,11 +665,23 @@ def __init__(self, vgg_file_paths, *args, **kwargs):
662665 super ().__init__ (* args , ** kwargs )
663666
664667
665- def generate (self , path_only = False , outflag = _cv2 .IMREAD_UNCHANGED ):
668+ def generate (self , path_only = False , outflag = _cv2 .IMREAD_UNCHANGED , file_attr_match = None ):
669+ '''(bool, int, dict|None) -> ndarray|None, str, dict
670+ Generate images and paths, dict will be empty.
671+
672+ file_attr_match:
673+ a dictionary which is checked for a partial
674+ match against the image file attributes,
675+ eg {'is_train'=1}
676+
677+ Example:
678+ >>>for Img, pth, _ in VGGImages.generate(file_attr_match={'train'=1}):
679+ #do some work
680+ '''
666681 for vgg_file in self .vgg_file_paths :
667682 try :
668683 _vgg .load_json (vgg_file )
669- for I in _vgg .imagesGenerator ():
684+ for I in _vgg .imagesGenerator (file_attr_match = file_attr_match ):
670685 if path_only :
671686 yield None , I .filepath , None
672687 continue
@@ -715,8 +730,8 @@ def __init__(self, vgg_file_paths, *args, region_attrs=None, **kwargs):
715730 super ().__init__ (* args , ** kwargs )
716731
717732
718- def generate (self , shape_type = 'rect' , region_attrs = None , path_only = False , outflag = _cv2 .IMREAD_UNCHANGED , skip_imghdr_check = False , grow_roi_proportion = 1 ):
719- '''(str|list|None, dict, bool, cv2.imread option, bool) -> ndarray|None, str, dict
733+ def generate (self , shape_type = 'rect' , region_attrs = None , path_only = False , outflag = _cv2 .IMREAD_UNCHANGED , skip_imghdr_check = False , grow_roi_proportion = 1 , file_attr_match = None ):
734+ '''(str|list|None, dict, bool, cv2.imread option, bool, dict ) -> ndarray|None, str, dict
720735 Yields the images with the bounding boxes and category name of all objects
721736 in the pascal voc images
722737
@@ -742,7 +757,9 @@ def generate(self, shape_type='rect', region_attrs=None, path_only=False, outfla
742757 grow_roi_percent:
743758 increase or decreaese roi by this percentage of the
744759 original roi.
745-
760+ file_attr_match:
761+ If not None, only regions from images with the matching file attributes
762+ will be generated
746763
747764 Yields:
748765 image, path, region_attributes dict
@@ -759,7 +776,7 @@ def generate(self, shape_type='rect', region_attrs=None, path_only=False, outfla
759776 for vgg_file in self .vgg_file_paths :
760777 try :
761778 _vgg .load_json (vgg_file )
762- for I in _vgg .imagesGenerator (skip_imghdr_check = skip_imghdr_check ):
779+ for I in _vgg .imagesGenerator (skip_imghdr_check = skip_imghdr_check , file_attr_match = file_attr_match ):
763780 for reg in I .roi_generator (shape_type , self .region_attrs ):
764781 assert isinstance (reg , _vgg .Region )
765782 if path_only :
0 commit comments