コード例 #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--player", help="player 1-6", type=int, default=1)
    args = parser.parse_args()

    config = Config(CONFIG_FILE, args.player)

    comms_config = {
        'rx_ip': config.client_ip,
        'rx_port': config.client_port,
        'tx_ip': config.sim_ip,
        'tx_port': config.sim_port
    }
    print("Rx at {}:{}".format(comms_config["rx_ip"], comms_config["rx_port"]))
    print("Tx to {}:{}".format(comms_config["tx_ip"], comms_config["tx_port"]))

    commands_mutex = Lock()

    # Launch comms in background thread
    comms = CommsThread(comms_config, False, commands_mutex)
    comms.daemon = True
    comms.start()

    # Launch perception, motion planning, and controls in main thread
    sweep_builder = SweepBuilder()
    perception = Perception(config)
    planning = Planning(config)
    controls = Controls(config)
    visualize = Visualize(config)

    try:
        while True:
            vehicle_state = sweep_builder.run(comms.get_vehicle_states())
            if vehicle_state is not None:
                t1 = time.time()

                world_state = perception.run(vehicle_state)
                plan = planning.run(world_state)
                vehicle_commands = controls.run(plan)

                t2 = time.time()
                freq = 1 / (t2 - t1)
                print(f"Running at {freq} Hz")

                vehicle_commands['draw'] = visualize.run(world_state, plan)
                with commands_mutex:
                    # hold the lock to prevent the Comms thread from
                    # sending the commands dict while we're modifying it
                    comms.vehicle_commands.update(vehicle_commands)
    except KeyboardInterrupt:
        pass
コード例 #2
0
def main(argv):
    # setup options from command line
    netType = 'ResNet'
    input_shape1 = 224
    input_shape2 = 224
    gaus = 0
    numberOfEpochs = 30
    hiddenUnits = 75
    patients_to_use = 'ALL'
    weights = ''
    folder = "D:\\deep learning dataset\\MS Fall Study"
    try:
        opts, args = getopt.getopt(argv, "?f:t:1:2:g:e:h:p:w:")
    except getopt.GetoptError:
        Help()
        return
    for opt, arg in opts:
        if opt == '-?':
            Help()
            return
        elif opt == '-f':
            folder = arg
        elif opt == '-w':
            weights = arg
        elif opt == '-t':
            netType = arg
        elif opt == '-1':
            input_shape1 = int(arg)
        elif opt == '-2':
            input_shape2 = int(arg)
        elif opt == '-g':
            gaus = float(arg)
        elif opt == '-e':
            numberOfEpochs = int(arg)
        elif opt == '-h':
            hiddenUnits = int(arg)
        elif opt == '-p':
            try:
                patients_to_use = int(arg)
            except ValueError:
                patients_to_use = arg

    if 'Plt' == netType:
        vis = Visualize(folder, patients_to_use, True)
        vis.run()
    elif 'Img' == netType:
        vis = Visualize(folder, patients_to_use, False)
        vis.run()
    elif 'Table' == netType:
        table = DataTable(folder)
        table.run()
    else:
        netTypeVal = GetType(netType)
        if NETTYPE_INVALID == netTypeVal:
            print('unknown tpye:', netType)
            return
        print(
            '##################################################################################'
        )
        print(
            '# {0:s} shape ({1:d}, {2:d}) epochs {3:d} gaus {4:f} hidden units {5:d}          #'
            .format(netType, input_shape1, input_shape2, numberOfEpochs, gaus,
                    hiddenUnits))
        print(
            '##################################################################################'
        )
        rgb = True
        twoD = False
        batchSize = 32
        input_shape = (input_shape1, input_shape2)
        activities_to_load = [
            "30s Chair Stand Test", "Tandem Balance Assessment",
            "Standing Balance Assessment", "Standing Balance Eyes Closed",
            "ADL: Normal Walking", "ADL: Normal Standing",
            "ADL: Normal Sitting", "ADL: Slouch sitting", "ADL: Lying on back",
            "ADL: Lying on left side", "ADL: Lying on right side"
        ]
        preLoader = MatrixPreLoader(dataset_directory=folder,
                                    patients_to_use=patients_to_use,
                                    activity_types=activities_to_load,
                                    print_loading_progress=True)
        num_features = preLoader.get_number_of_patients()
        if NETTYPE_VGGBN == netTypeVal:
            vgg = VGG16Imp()
            model = vgg.VGG16WithBN(input_shape=(input_shape1, input_shape2,
                                                 3),
                                    classes=num_features)
        elif NETTYPE_VGG16 == netTypeVal:
            model = VGG16(weights=None,
                          classes=num_features,
                          input_shape=(input_shape1, input_shape2, 3))
        elif NETTYPE_RESNET == netTypeVal:
            resnet = ResNetImp()
            model = resnet.ResNet((input_shape1, input_shape2, 3),
                                  num_features)
        elif NETTYPE_RESNETPT == netTypeVal or NETTYPE_RESNETPD == netTypeVal:
            resnet = ResNetImp()
            model = resnet.ResNetP(weights, (input_shape1, input_shape2, 3),
                                   num_features)
        elif NETTYPE_SIMPLE == netTypeVal:
            rgb = False
            twoD = True
            rnn = RNNImp(hiddenUnits)
            model = rnn.SimpleRNN(input_shape, num_features)
        elif NETTYPE_GRU == netTypeVal:
            rgb = False
            twoD = True
            rnn = RNNImp(hiddenUnits)
            model = rnn.GRU(input_shape, num_features)
        elif NETTYPE_LSTM == netTypeVal:
            rgb = False
            twoD = True
            rnn = RNNImp(hiddenUnits)
            model = rnn.LSTM(input_shape, num_features)
        else:
            return

        print("create_generators")
        training_gen, validation_gen = create_generators(
            preLoader, input_shape, rgb, twoD, gaus, batchSize)

        if NETTYPE_RESNETPD == netTypeVal:
            print("predict_with_generator")
            predict_with_generator(model, validation_gen, preLoader)
        else:
            print("train_model_with_generator")
            train_model_with_generator(model, training_gen, validation_gen,
                                       numberOfEpochs, netType)

            training_dist = training_gen.GetDistribution()
            validation_dist = validation_gen.GetDistribution()
            print('training distribution', training_dist)
            print('validation distribution', validation_dist)