Exemple #1
0
import numpy as np
import tensorflow as tf
from environments.coppeliagym import CoppeliaEnv
from utils.utils import setup, create_world
import collections

args = ['--ee_j_pos', '--vrep', '--render']
args = setup(args)
env, agent = create_world(args)

for eps in range(10):
    state = env.reset()
    env.render()
    for t in range(args.time_limit):
        if t < 150:
            action = env.action_space.high
        else:
            action = env.action_space.low
        np.putmask(action, [1, 1, 1, 1, 0, 1, 1, 1], 0)
        next_state, *_ = env.step(action)
        print(next_state[7])
Exemple #2
0
        images1: np.array, shape: (N, H, W, 3), dtype: np.float32 between 0-1 or np.uint8
        images2: np.array, shape: (N, H, W, 3), dtype: np.float32 between 0-1 or np.uint8
        use_multiprocessing: If multiprocessing should be used to pre-process the images
        batch size: batch size used for inception network
    Returns:
        FID (scalar)
    """
    mu1, sigma1 = calculate_activation_statistics(images1, batch_size, device)
    mu2, sigma2 = calculate_activation_statistics(images2, batch_size, device)
    fid = calculate_frechet_distance(mu1, sigma1, mu2, sigma2)
    return fid


if __name__ == "__main__":

    FLAGS, logger = setup(running_script="./utils/models.py",
                          config="./config.json")
    input_path = FLAGS.input
    valid_path = FLAGS.valid
    device = FLAGS.device if torch.cuda.is_available() else "cpu"
    network_dir = f'{FLAGS.path_prefix}/models/{FLAGS.network_name}'

    print("\nCalculate FID-Score...")
    file = open(f"{network_dir}/fid_{FLAGS.network_name}.txt", 'w')
    gen_train_path = f"{network_dir}/generated_train_images/"
    gen_valid_path = f"{network_dir}/generated_valid_images/"

    num_images = len(os.listdir(gen_train_path))
    batch_size = 32
    image_size = 128

    for path1, path2 in [(gen_train_path, input_path),
Exemple #3
0
        np.concatenate([state, agent.transitbuffer.goal]))
    return action


def mock_goal_action(agent, state):
    agent.select_action(state)
    if agent.transitbuffer.meta_time:
        agent.transitbuffer.goal = mock_goal
    action = agent.sub_agent.select_action(
        np.concatenate([state, agent.transitbuffer.goal]))
    return action


if __name__ == "__main__":
    # Parse Arguments and create directories
    args = setup(sys.argv[1:])
    env, agent = create_world(args)
    #agent.load_model(f"./EXPERIMENTS/directional_10_0_1M/model/{agent.file_name}")
    #agent.load_model(f"./EXPERIMENTS/absolute_10_0/model/{agent.file_name}")
    #agent.load_model(f"./EXPERIMENTS/absolute_left_right_10/model/{agent.file_name}")
    #agent.load_model(f"./EXPERIMENTS/6m_absolute_left_right_up_down/{agent.file_name}")
    #agent.load_model(f"./EXPERIMENTS/2m_full_hiro_agent_15_5/model/{agent.file_name}")
    agent.load_model(f"./models/{agent.file_name}")
    state, done = env.reset(), False
    episode_reward = 0
    episode_timesteps = 0
    episode_num = 0
    second_bot = init_kuka()
    init_state = state
    while True:
        second_bot.set_joint_positions(init_state[:7])

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description="""Training VAE""")
    parser.add_argument('imfolder',
                        type=str,
                        default=None,
                        metavar='image_dir',
                        help="""The path to the directory which contains
                        the imgge folder. The images themselves must be
                        in one or more subdirectories of the imfolder""")
    args, rest = parser.parse_known_args()

    FLAGS, logger = setup(running_script="./utils/training.py",
                          args=rest,
                          config="config.json")
    print("FLAGS= ", FLAGS)

    imfolder = os.path.abspath(args.imfolder)

    device = FLAGS.device if torch.cuda.is_available() else "cpu"

    print("\ninput dir: ", imfolder, "\ndevice: ", device)

    os.makedirs(FLAGS.path_prefix, exist_ok=True)
    if FLAGS.networkname in os.listdir(FLAGS.path_prefix):
        input1 = input(
            "\nNetwork already exists. Are you sure to proceed? ([y]/n) ")
        if not input1 in ['y', 'yes']:
            sys.exit()
Exemple #5
0
# Setup logging and creates save dir
if args.logging:
    args.experiment_dir, writer = setup_logging(args, 
                                                default_args, 
                                                args.args_to_ignore.split(','), 
                                                exp_name_use_date=True)

    args.experiment_dir = Path(args.experiment_dir)


# Dump args
save_yaml(vars(args), f'{args.experiment_dir}/args.yaml')

# Setup everything else
setup(args)


# Load dataloaders
model_native_transform = m['model'].get_native_transform()
dataloader_train       = m['dataloader'].get_dataloader(args, model_native_transform, part='train', phase='train')
dataloader_val         = m['dataloader'].get_dataloader(args, model_native_transform, part='val',   phase='val')


# Load criterion
criterion = get_criterion(args.criterion, args).to(args.device)


# Load model 
model = m['model'].get_net(args, dataloader_train, criterion)