(image_roots, classification=False,
        intersection=False, filter_tuples=None, verbose=None)
return tuples, classes, class_to_idx
Returns ([(img1, img2, clsid), (img1, img2, clsid)..],
             classes, class_to_idx)
Returns ([(img1, img2, clsid), (img1, img2, clsid)..],
             classes, class_to_idx)
Returns ( [ ( img1 img2 clsid ) ( img1 img2 clsid ) .. ] classes class_to_idx )
def make_parallel_dataset(image_roots, classification=False,
        intersection=False, filter_tuples=None, verbose=None):
    """
    Returns ([(img1, img2, clsid), (img1, img2, clsid)..],
             classes, class_to_idx)
    """
    image_roots = [os.path.expanduser(d) for d in image_roots]
    image_sets = OrderedDict()
    for j, root in enumerate(image_roots):
        for path in walk_image_files(root, verbose=verbose):
            key = os.path.splitext(os.path.relpath(path, root))[0]
            if key not in image_sets:
                image_sets[key] = []
            if not intersection and len(image_sets[key]) != j:
                raise RuntimeError(
                    'Images not parallel: %s missing from one dir' % (key))
            image_sets[key].append(path)
    if classification:
        classes = sorted(set([os.path.basename(os.path.dirname(k))
            for k in image_sets.keys()]))
        class_to_idx = dict({k: v for v, k in enumerate(classes)})
        for k, v in image_sets.items():
            v.append(class_to_idx[os.path.basename(os.path.dirname(k))])
    else:
        classes, class_to_idx = None, None
    tuples = []
    for key, value in image_sets.items():
        if len(value) != len(image_roots) + (1 if classification else 0):
            if intersection:
                continue
            else:
                raise RuntimeError(
                    'Images not parallel: %s missing from one dir' % (key))
        value = tuple(value)
        if filter_tuples and not filter_tuples(value):
            continue
        tuples.append(value)
    return tuples, classes, class_to_idx
def make_parallel_dataset ( image_roots , classification = False , intersection = False , filter_tuples = None , verbose = None ) : image_roots = [ os . path . expanduser ( d ) for d in image_roots ] image_sets = OrderedDict ( ) for j , root in enumerate ( image_roots ) : for path in walk_image_files ( root , verbose = verbose ) : key = os . path . splitext ( os . path . relpath ( path , root ) ) [ 0 ] if key not in image_sets : image_sets [ key ] = [ ] if not intersection and len ( image_sets [ key ] ) != j : raise RuntimeError ( 'Images not parallel: %s missing from one dir' % ( key ) ) image_sets [ key ] . append ( path ) if classification : classes = sorted ( set ( [ os . path . basename ( os . path . dirname ( k ) ) for k in image_sets . keys ( ) ] ) ) class_to_idx = dict ( { k : v for v , k in enumerate ( classes ) } ) for k , v in image_sets . items ( ) : v . append ( class_to_idx [ os . path . basename ( os . path . dirname ( k ) ) ] ) else : classes , class_to_idx = None , None tuples = [ ] for key , value in image_sets . items ( ) : if len ( value ) != len ( image_roots ) + ( 1 if classification else 0 ) : if intersection : continue else : raise RuntimeError ( 'Images not parallel: %s missing from one dir' % ( key ) ) value = tuple ( value ) if filter_tuples and not filter_tuples ( value ) : continue tuples . append ( value ) return tuples , classes , class_to_idx