Ejemplo n.º 1
0
def main(env, demo_dir, skip, graph, save_logs, view, render):

    gym_env = gym.make(env)
    paths = []
    print("Scanning demo_dir: " + demo_dir + "=========")
    print(glob.glob(demo_dir + "/**/*.mjl", recursive=True))
    for ind, file in enumerate(
            glob.glob(demo_dir + "/**/*.mjl", recursive=True)):

        # process logs
        print("processing: " + file, end=': ')

        data = parse_mjl_logs(file, skip)

        print("log duration %0.2f" % (data['time'][-1] - data['time'][0]))

        # plot logs
        if (graph):
            print("plotting: " + file)
            viz_parsed_mjl_logs(data)

        # save logs
        if (save_logs):
            pickle.dump(data, open(file[:-4] + ".pkl", 'wb'))

        # render logs to video
        if view == 'render':
            pass
            # render_demos(
            #     gym_env,
            #     data,
            #     filename=data['logName'][:-4] + '_demo_render.mp4',
            #     render=render)

        # playback logs and gather data
        elif view == 'playback':
            try:
                obs, act,init_qpos, init_qvel = gather_training_data(gym_env, data,\
                filename=data['logName'][:-4]+'_playback.mp4', render=render)
            except Exception as e:
                print(e)
                continue
            path = {
                'observations': obs,
                'actions': act,
                'goals': obs,
                'init_qpos': init_qpos,
                'init_qvel': init_qvel
            }
            paths.append(path)
            # accept = input('accept demo?')
            # if accept == 'n':
            #     continue
            pickle.dump(path,
                        open(demo_dir + env + str(ind) + "_path.pkl", 'wb'))
            pickle.dump(path,
                        open(demo_dir + env + str(ind) + "_path.pkl", 'wb'))
            print(demo_dir + env + file + "_path.pkl")
Ejemplo n.º 2
0
def main(env, demo_dir, skip, graph, save_logs, view, render):

    gym_env = gym.make(env)
    paths = []
    print("Scanning demo_dir: " + demo_dir + "=========")
    for ind, file in enumerate(glob.glob(demo_dir + "*.mjl")):

        # process logs
        print("processing: " + file, end=": ")

        data = parse_mjl_logs(file, skip)

        print("log duration %0.2f" % (data["time"][-1] - data["time"][0]))

        # plot logs
        if graph:
            print("plotting: " + file)
            viz_parsed_mjl_logs(data)

        # save logs
        if save_logs:
            pickle.dump(data, open(file[:-4] + ".pkl", "wb"))

        # render logs to video
        if view == "render":
            render_demos(
                gym_env,
                data,
                filename=data["logName"][:-4] + "_demo_render.mp4",
                render=render,
            )

        # playback logs and gather data
        elif view == "playback":
            try:
                obs, act, init_qpos, init_qvel = gather_training_data(
                    gym_env,
                    data,
                    filename=data["logName"][:-4] + "_playback.mp4",
                    render=render,
                )
            except Exception as e:
                print(e)
                continue
            path = {
                "observations": obs,
                "actions": act,
                "goals": obs,
                "init_qpos": init_qpos,
                "init_qvel": init_qvel,
            }
            paths.append(path)
            # accept = input('accept demo?')
            # if accept == 'n':
            #     continue
            pickle.dump(path, open(demo_dir + env + str(ind) + "_path.pkl", "wb"))
            print(demo_dir + env + file + "_path.pkl")
Ejemplo n.º 3
0
def main(env, demo_dir, skip, graph, save_logs, view, render):

    gym_env = gym.make(env)
    #paths = []

    #demo_dirs = ["friday_kettle_bottomknob_hinge_slide", "friday_kettle_bottomknob_switch_slide",
    #    "friday_kettle_switch_hinge_slide", "friday_kettle_topknob_bottomknob_slide",
    #    "friday_kettle_topknob_switch_slide", "friday_microwave_bottomknob_hinge_slide",
    #    "friday_microwave_bottomknob_switch_slide", "friday_microwave_kettle_bottomknob_hinge",
    #    "friday_microwave_kettle_bottomknob_slide","friday_microwave_kettle_hinge_slide",
    #    "friday_microwave_kettle_switch_slide", "friday_microwave_kettle_topknob_hinge"]

    demo_dirs = [
        "friday_microwave_kettle_topknob_switch",
        "friday_microwave_topknob_bottomknob_hinge",
        "friday_microwave_topknob_bottomknob_slide",
        "friday_topknob_bottomknob_switch_slide",
        "postcorl_kettle_bottomknob_switch_hinge",
        "postcorl_kettle_topknob_bottomknob_hinge",
        "postcorl_kettle_topknob_bottomknob_switch",
        "postcorl_microwave_bottomknob_switch_slide",
        "postcorl_microwave_kettle_switch_hinge",
        "postcorl_microwave_switch_hinge_slide",
        "postcorl_microwave_topknob_bottomknob_switch",
        "postcorl_microwave_topknob_switch_hinge"
    ]
    #create dirs
    video_dir = "./videos/"
    data_dir = "./data/"
    Path(video_dir).mkdir(parents=True, exist_ok=True)
    Path(data_dir).mkdir(parents=True, exist_ok=True)

    for demo_dir in demo_dirs:
        print("Scanning demo_dir: " + demo_dir + "=========")
        comp_demo_dir = "./kitchen_demos_multitask/" + demo_dir + "/"
        for ind, file in enumerate(glob.glob(comp_demo_dir + "*.mjl")):

            # process logs
            print("processing: " + file, end=': ')

            data = parse_mjl_logs(file, skip)

            print("log duration %0.2f" % (data['time'][-1] - data['time'][0]))

            # plot logs
            if (graph):
                print("plotting: " + file)
                viz_parsed_mjl_logs(data)

            # save logs
            if (save_logs):
                pickle.dump(data, open(file[:-4] + ".pkl", 'wb'))

            # render logs to video
            if view == 'render':
                render_demos(gym_env,
                             data,
                             filename=data['logName'][:-4] +
                             '_demo_render.mp4',
                             render=render)

            # playback logs and gather data
            elif view == 'playback':
                try:
                    obs, imgs, act, init_qpos, init_qvel = gather_training_data(gym_env, data,\
                    filename=video_dir + demo_dir + "_" + str(ind) + '.mp4', render=render)
                    #data['logName'][:-4]+'_playback.mp4', render=render)
                except Exception as e:
                    print(e)
                    continue
                path = {
                    'observations': obs,
                    'images': imgs,
                    'actions': act,
                    'goals': obs,
                    'init_qpos': init_qpos,
                    'init_qvel': init_qvel
                }
                #paths.append(path)
                pickle.dump(
                    path,
                    open(data_dir + demo_dir + "_" + str(ind) + "_path.pkl",
                         'wb'))