once-for-all-GM/data/dataset/single_label_dataset.py
def to_imglist():
    '''
    by huangguowei: generate train or val meta file.
    :param root:
    :return:
    '''
    import pydash
    root = "/home/huang/huang/data/ILSVRC/Data/CLS-LOC/train"
    meta_train_path = "/home/huang/huang/data/ILSVRC/meta/train.txt"

    mpa_clsloc = "/home/huang/huang/data/ILSVRC/devkit/data/map_clsloc.txt"

    root = root if root.endswith("/") else root + "/"
    lines = open(mpa_clsloc, "r").readlines()
    # lines ['n02119789 1 kit_fox\n', 'n02100735 2 English_setter\n', 'n02110185 3 Siberian_husky\n']
    print("lines", lines[:3])

    def get_class_name_id(line):
        line_split = line.strip().split(maxsplit=2)
        # class_id starts from 0.
        class_id = int(line_split[1]) - 1
        return line_split[0], class_id

    class_name_id_dict = dict(pydash.map_(lines, get_class_name_id))

    paths = sorted(glob(os.path.join(root, '*/*.JPEG')))
    print("paths", paths[:3])


    def parse_jpeg_path(full_path):
        relative_path = pydash.replace(full_path, root, "")
        last_slash_index = pydash.last_index_of(relative_path, "/")
        class_name = relative_path[:last_slash_index]
        # print("class_name", class_name)
        class_id = class_name_id_dict[class_name]
        return relative_path, class_id

    paths_with_id = pydash.map_(paths, parse_jpeg_path)

    with open(meta_train_path, "w") as file:
        pydash.map_(paths_with_id, lambda kv: file.write(pydash.join(kv, " ") + '\n'))

    return 0

    by huangguowei: generate train or val meta file.
    :param root:
    :return:
    
by huangguowei: generate train or val meta file.
by huangguowei : generate train or val meta file .
def to_imglist():
    import pydash
    root = "/home/huang/huang/data/ILSVRC/Data/CLS-LOC/train"
    meta_train_path = "/home/huang/huang/data/ILSVRC/meta/train.txt"
    mpa_clsloc = "/home/huang/huang/data/ILSVRC/devkit/data/map_clsloc.txt"
    root = root if root.endswith("/") else root + "/"
    lines = open(mpa_clsloc, "r").readlines()
    print("lines", lines[:3])
    def get_class_name_id(line):
        line_split = line.strip().split(maxsplit=2)
        class_id = int(line_split[1]) - 1
        return line_split[0], class_id
    class_name_id_dict = dict(pydash.map_(lines, get_class_name_id))
    paths = sorted(glob(os.path.join(root, '*/*.JPEG')))
    print("paths", paths[:3])
    def parse_jpeg_path(full_path):
        relative_path = pydash.replace(full_path, root, "")
        last_slash_index = pydash.last_index_of(relative_path, "/")
        class_name = relative_path[:last_slash_index]
        class_id = class_name_id_dict[class_name]
        return relative_path, class_id
    paths_with_id = pydash.map_(paths, parse_jpeg_path)
    with open(meta_train_path, "w") as file:
        pydash.map_(paths_with_id, lambda kv: file.write(pydash.join(kv, " ") + '\n'))
    return 0
def to_imglist ( ) : import pydash root = "/home/huang/huang/data/ILSVRC/Data/CLS-LOC/train" meta_train_path = "/home/huang/huang/data/ILSVRC/meta/train.txt" mpa_clsloc = "/home/huang/huang/data/ILSVRC/devkit/data/map_clsloc.txt" root = root if root . endswith ( "/" ) else root + "/" lines = open ( mpa_clsloc , "r" ) . readlines ( ) print ( "lines" , lines [ : 3 ] ) def get_class_name_id ( line ) : line_split = line . strip ( ) . split ( maxsplit = 2 ) class_id = int ( line_split [ 1 ] ) - 1 return line_split [ 0 ] , class_id class_name_id_dict = dict ( pydash . map_ ( lines , get_class_name_id ) ) paths = sorted ( glob ( os . path . join ( root , '*/*.JPEG' ) ) ) print ( "paths" , paths [ : 3 ] ) def parse_jpeg_path ( full_path ) : relative_path = pydash . replace ( full_path , root , "" ) last_slash_index = pydash . last_index_of ( relative_path , "/" ) class_name = relative_path [ : last_slash_index ] class_id = class_name_id_dict [ class_name ] return relative_path , class_id paths_with_id = pydash . map_ ( paths , parse_jpeg_path ) with open ( meta_train_path , "w" ) as file : pydash . map_ ( paths_with_id , lambda kv : file . write ( pydash . join ( kv , " " ) + '\n' ) ) return 0
by huangguowei: generate train or val meta file.
by huangguowei : generate train or val meta file .
'''
    by huangguowei: generate train or val meta file.
    :param root:
    :return:
    ''' # lines ['n02119789 1 kit_fox\n', 'n02100735 2 English_setter\n', 'n02110185 3 Siberian_husky\n'] # class_id starts from 0. # print("class_name", class_name)
None
root
None