def gen_split_supervision(root_dir):
    Dataset = []
    Labels = []
    NumFrames = []
    data_mmaps=[]
    root_dir = os.path.join(root_dir, 'frames')
    for dir_user in sorted(os.listdir(root_dir)):
        class_id = 0
        dir = os.path.join(root_dir, dir_user)
        for target in sorted(os.listdir(dir)):
            dir1 = os.path.join(dir, target)
            insts = sorted(os.listdir(dir1))
            if insts != []:
                for inst in insts:
                    inst_dir = os.path.join(dir1, inst, "rgb")
                    if os.path.isdir(inst_dir)==False:
                      continue
                    inst_dir_mmaps = os.path.join(dir1, inst, "mmaps")
                    numFrames_mmaps = len(glob.glob1(inst_dir_mmaps, '*.png'))
                    numFrames = len(glob.glob1(inst_dir, '*.png'))

                    Dataset.append(inst_dir)
                    Labels.append(class_id)
                    NumFrames.append(numFrames)
                    data_mmaps.append(inst_dir_mmaps)
            class_id += 1
    return Dataset, Labels, NumFrames, data_mmaps
def gen_split(root_dir, stackSize, user, fmt=".png"):
    fmt = "*" + fmt
    class_id = 0

    Dataset = []
    Labels = []
    NumFrames = []
    try:
        dir_user = os.path.join(root_dir, 'processed_frames2', user)
        for target in sorted(os.listdir(dir_user)):
            if target.startswith('.'):
                continue
            target = os.path.join(dir_user, target)
            insts = sorted(os.listdir(target))
            if insts != []:
                for inst in insts:
                    if inst.startswith('.'):
                        continue
                    inst_rgb = os.path.join(target, inst, "rgb")
                    numFrames = len(glob.glob1(inst_rgb, fmt))
                    if numFrames >= stackSize:
                        Dataset.append(target + '/' + inst)
                        Labels.append(class_id)
                        NumFrames.append(numFrames)
            class_id += 1
    except:
        print('error')
    return Dataset, Labels, NumFrames
Exemplo n.º 3
0
def gen_split(root_dir, stackSize, phase):
    Dataset = []
    Labels = []
    NumFrames = []
    root_dir = os.path.join(root_dir, 'processed_frames2') #GTEA61/processed_frames2/
    
    for dir_user in sorted(os.listdir(root_dir)): #S1/
        if dir_user=='.DS_Store': continue
        if (phase=='train') ^ (dir_user=="S2"):
            dir = os.path.join(root_dir, dir_user) #GTEA61/processed_frames2/S1/
            class_id=0
            
            for target in sorted(os.listdir(dir)): #close_choco/
                if target=='.DS_Store': continue
                dir1 = os.path.join(dir, target) #GTEA61/processed_frames2/S1/close_choco/
                
                insts = sorted(os.listdir(dir1)) #1/
                if insts != []:
                    for inst in insts:
                        if inst=='.DS_Store': continue
                        
                        inst_dir = os.path.join(dir1, inst+"/rgb") #GTEA61/processed_frames2/S1/close_choco/1/rgb/
                        numFrames = len(glob.glob1(inst_dir, '*.png'))
                        
                        if numFrames >= stackSize:
                            Dataset.append(inst_dir)
                            Labels.append(class_id)
                            NumFrames.append(numFrames)
                class_id += 1
    return Dataset, Labels, NumFrames
Exemplo n.º 4
0
def gen_split(root_dir, stackSize, fmt, users):
    Dataset = []
    Labels = []
    NumFrames = []
    root_dir = os.path.join(root_dir, 'processed_frames2')
    for dir_user in sorted(os.listdir(root_dir)):
        if dir_user not in users:
            continue
        class_id = 0
        dir = os.path.join(root_dir, dir_user)
        for target in sorted(os.listdir(dir)):
            dir1 = os.path.join(dir, target)
            if not os.path.isdir(dir1):
                continue
            insts = sorted(os.listdir(dir1))
            if insts != []:
                for inst in insts:
                    inst_dir = os.path.join(dir1, inst)
                    inst_dir = os.path.join(inst_dir, 'flow_surfaceNormals')
                    termination = f'*{fmt}'
                    numFrames = len(glob.glob1(inst_dir, termination))
                    if numFrames >= stackSize:
                        Dataset.append(inst_dir)
                        Labels.append(class_id)
                        NumFrames.append(numFrames)
            class_id += 1
    print(f'Dataset size: {len(Dataset)} images')
    return Dataset, Labels, NumFrames
Exemplo n.º 5
0
def gen_split(root_dir, splits, stack_size):
    Dataset = []
    Labels = []
    NumFrames = []

    # root_dir  =  #drive/.../GTEA61/processed_frames/
    for split in splits:  # root_dir/SX
        dir1 = os.path.join(root_dir, split)
        #print(dir1)
        class_id = 0
        for target in sorted(os.listdir(dir1)):  # root_dir/SX/target/
            dir2 = os.path.join(dir1, target)
            #print(dir2)
            insts = sorted(os.listdir(dir2))  # root_dir/SX/target/Y
            if insts:
                for inst in insts:
                    inst_dir = os.path.join(dir2, inst)
                    numFrames = len(
                        glob.glob1(os.path.join(inst_dir, 'rgb'),
                                   '*[0-9].png'))
                    if numFrames >= stack_size:
                        Dataset.append(inst_dir)
                        Labels.append(class_id)
                        NumFrames.append(numFrames)

            class_id += 1
    return Dataset, Labels, NumFrames
Exemplo n.º 6
0
def gen_split(root_dir, stackSize):
    Dataset = []

    Labels = []
    New_dir = ['kenya_3', 'kenya_4', 'oxford_3', 'oxford_4', 'oxford_5']
    label_name = [
        'chat', 'clean', 'drink', 'dryer', 'machine', 'microwave', 'mobile',
        'paper', 'print', 'read', 'shake', 'staple', 'take', 'typeset', 'walk',
        'wash', 'whiteboard', 'write'
    ]
    for subject_folder in os.listdir(root_dir):
        dir = os.path.join(root_dir, subject_folder)
        for target in sorted(os.listdir(dir)):
            if subject_folder in New_dir:  # Videos from test_dataset_1
                video_name = target.split(".")[0]
                num_label = video_name.split("-")[0]
                label = re.split('(\d+)', num_label)[-1]
            elif subject_folder not in New_dir:  # Videos from segmented folders
                video_name = target.split(".")[0]
                label = video_name.split("_")[-1]
            if label == 'wave' or label == 'open':
                continue
            Dataset.append(os.path.join(dir, target))
            for i in range(0, len(label_name)):
                if label == label_name[i]:
                    label_id = i
                    break
                if label == "dry":
                    label_id = 3
                    break
            Labels.append(label_id)
    return Dataset, Labels
Exemplo n.º 7
0
def gen_split(root_dir, stackSize, train):
    Dataset = []
    Labels = []
    NumFrames = []
    ActionLabels = {}
    root_dire = os.path.join(root_dir, 'processed_frames2')
    for dir_user in sorted(os.listdir(root_dire)):
        class_id = 0
        dir1 = os.path.join(root_dire, dir_user)
        if os.path.isfile(dir1):
            continue
        if train == True:
            if dir_user == 'S1' or dir_user == 'S3' or dir_user == 'S4':
                for target in sorted(os.listdir(dir1)):
                    if target in ActionLabels.keys():
                        class_id = ActionLabels[target]
                    else:
                        ActionLabels[target] = class_id
                    dir2 = os.path.join(dir1, target)
                    if os.path.isfile(dir2):
                        continue
                    insts = sorted(os.listdir(dir2))
                    if insts != []:
                        for inst in insts:
                            inst_dir = os.path.join(dir2, inst)
                            inst_dir = os.path.join(inst_dir, 'rgb')
                            numFrames = len(glob.glob1(
                                inst_dir, '*.png')) - len(
                                    glob.glob1(inst_dir, '*(1).png'))
                            if numFrames >= stackSize:
                                Dataset.append(inst_dir)
                                Labels.append(class_id)
                                NumFrames.append(numFrames)
                    class_id += 1
        else:
            if dir_user == 'S2':
                for target in sorted(os.listdir(dir1)):
                    if target in ActionLabels.keys():
                        class_id = ActionLabels[target]
                    else:
                        ActionLabels[target] = class_id
                    dir2 = os.path.join(dir1, target)
                    if os.path.isfile(dir2):
                        continue
                    insts = sorted(os.listdir(dir2))
                    if insts != []:
                        for inst in insts:
                            inst_dir = os.path.join(dir2, inst)
                            inst_dir = os.path.join(inst_dir, 'rgb')
                            numFrames = len(glob.glob1(
                                inst_dir, '*.png')) - len(
                                    glob.glob1(inst_dir, '*(1).png'))
                            if numFrames >= stackSize:
                                Dataset.append(inst_dir)
                                Labels.append(class_id)
                                NumFrames.append(numFrames)
                    class_id += 1
    return Dataset, Labels, NumFrames
Exemplo n.º 8
0
def gen_split(root_dir, stackSize):
    Dataset = []
    for target in os.listdir(root_dir):
        video_name = target.split(".")[0]
        label = video_name.split("_")[-1]
        if label == 'wave' or label == 'open':
            continue
        Dataset.append(os.path.join(root_dir, target))

    return Dataset
Exemplo n.º 9
0
def gen_split(root_dir, stackSize):
    # DatasetX = []
    # DatasetY = []
    DatasetIdt = []
    Dataset = []
    Labels = []
    NumFrames = []
    FramesMaps = []

    root_dir = os.path.join(root_dir, 'processed_frames2')
    for dir_user in sorted(os.listdir(root_dir)):
        if not dir_user.startswith('.') and dir_user:
            class_id = 0
            directory = os.path.join(root_dir, dir_user)
            action = sorted(os.listdir(directory))
            for target in sorted(os.listdir(directory)):
                if not target.startswith('.'):
                    directory1 = os.path.join(directory, target)
                    insts = sorted(os.listdir(directory1))
                    if insts != []:
                        for inst in insts:
                            inst_dir = os.path.join(directory1, inst)
                            inst_dir_rgb = inst_dir + "/rgb"
                            inst_dir_map = inst_dir + "/mmaps"

                            numFrames = len(glob.glob1(inst_dir_rgb, '*.png'))
                            numFramesMaps = len(
                                glob.glob1(inst_dir_map, '*.png'))

                            if numFrames >= stackSize:
                                #DatasetX.append(inst_dir)
                                #DatasetY.append(inst_dir.replace('flow_x', 'flow_y'))
                                #inst_dir = inst_dir.replace('flow_x_processed', 'processed_frames2')
                                #inst_dir = inst_dir + "/rgb"
                                #DatasetF.append(inst_dir)
                                Dataset.append(inst_dir_rgb)
                                DatasetIdt.append(inst_dir_map)
                                Labels.append(class_id)
                                NumFrames.append(numFrames)
                                FramesMaps.append(numFramesMaps)

                    class_id += 1
    return DatasetIdt, Dataset, Labels, NumFrames, FramesMaps, action
Exemplo n.º 10
0
def gen_split(root_dir, stackSize):
    Dataset = []
    Labels = []
    NumFrames = []
    root_dir = os.path.join(root_dir, 'frames')
    for dir_user in sorted(os.listdir(root_dir)):
        class_id = 0
        dir = os.path.join(root_dir, dir_user)
        for target in sorted(os.listdir(dir)):
            dir1 = os.path.join(dir, target)
            insts = sorted(os.listdir(dir1))
            if insts != []:
                for inst in insts:
                    inst_dir = os.path.join(dir1, inst)
                    numFrames = len(glob.glob1(inst_dir, '*.jpg'))
                    if numFrames >= stackSize:
                        Dataset.append(inst_dir)
                        Labels.append(class_id)
                        NumFrames.append(numFrames)
            class_id += 1
    return Dataset, Labels, NumFrames
Exemplo n.º 11
0
def gen_split(root_dir, stackSize):
    Dataset = []
    Labels = []
    NumFrames = []
    root_dir = os.path.join(root_dir, 'processed_frames2')
    # print for debugging
    #print(f"root_dir: {root_dir}")
    for dir_user in sorted(os.listdir(root_dir)):
        if not dir_user.startswith('.') and dir_user:
            class_id = 0
            directory = os.path.join(root_dir, dir_user)
            # print for debugging
            #print(f"directory: {directory}")
            action = sorted(os.listdir(directory))
            for target in sorted(os.listdir(directory)):
                if not target.startswith('.'):
                    directory1 = os.path.join(directory, target)
                    # print for debugging
                    #print(f"directory1: {directory1}")
                    insts = sorted(os.listdir(directory1))
                    # print for debugging
                    #print(f"insts: {insts}")
                    if insts != []:
                        for inst in insts:
                            if not inst.startswith('.'):
                                # adding "rgb" to path becasue after the number there are
                                # both "rgb" and "mmap" directories
                                inst = inst + "/rgb"
                                inst_dir = os.path.join(directory1, inst)
                                # print for debugging
                                #print(f"inst_dir: {inst_dir}")
                                numFrames = len(glob.glob1(inst_dir, '*.png'))
                                # print for debugging
                                #print(f"numFrames: {numFrames}")
                                if numFrames >= stackSize:
                                    Dataset.append(inst_dir)
                                    Labels.append(class_id)
                                    NumFrames.append(numFrames)
                    class_id += 1
    return Dataset, Labels, NumFrames, action
Exemplo n.º 12
0
def gen_split(root_dir, stackSize, user, fmt=".jpg"):
    fmt = "*" + fmt
    class_id = 0

    Dataset = []
    Labels = []
    NumFrames = []

    try:
        dir_user = os.path.join(root_dir, 'processed_frames2', user)
        for target in sorted(os.listdir(dir_user)):
            if target.startswith('.'):
                continue
            target = os.path.join(dir_user, target)
            insts = sorted(os.listdir(target))
            if insts != []:
                for inst in insts:
                    if inst.startswith('.'):
                        continue
                    inst = os.path.join(target, inst)
                    hsv_dir = os.path.join(inst, 'HSV_opticalFlow')
                    #if os.path.exists(hsv_dir):
                    #    print('removing: ',hsv_dir)
                    #    shutil.rmtree(hsv_dir)
                    #print(os.path.exists(hsv_dir),os.path.exists(inst))
                    if not (os.path.exists(hsv_dir)):
                        generate_HSVOpticalFlow(inst)
                    numFrames = len(glob.glob1(hsv_dir, fmt))
                    if numFrames >= stackSize:
                        Dataset.append(hsv_dir)
                        Labels.append(class_id)
                        NumFrames.append(numFrames)
            class_id += 1
    except:
        print('error')
        traceback.print_exc()
    return Dataset, Labels, NumFrames