Beispiel #1
0
    def loss(self, x, y, match_by=20):
        #print(x)
        x = CustomLoss()(x)
        output = self.forward(x)

        #        loss_fn = nn.MSELoss()
        #        loss = loss_fn(output, y)
        loss = self.accuracy(output, y, match_by)
        #print(output)
        return loss
    def processParams(self, params):
        # Directory for experience
        directory = self.setupDir(params)
        # Set up generator
        generator = InputGenerator(
            self.gt,
            chunk_size=params["nb_timesteps"],
            batch_size=params["batch_size"],
        )
        # Set up model
        model = RNN(params)
        model = model.model
        # Set up loss
        loss = CustomLoss(
            lambda_roll=params["lambda_roll"],
            lambda_pitch=params["lambda_pitch"],
            lambda_yaw=params["lambda_yaw"],
            lambda_thrust=params["lambda_thrust"],
            loss_func=params["loss_func"],
        )
        decay = ReduceLROnPlateau(monitor='val_loss',
                                  factor=0.1,
                                  patience=2,
                                  verbose=1,
                                  min_lr=1e-6)
        # Set up loss
        optimizer = Adam(
            lr=params["lr"],
            decay=params["decay"],
            beta_1=0.9,
            beta_2=0.999,
            epsilon=1e-08,
        )

        # Set up callbacks
        mcp = ModelCheckpoint(
            directory + "/model.{epoch:03d}.h5",
            verbose=1,
            save_weights_only=False,
        )
        lrp = PrintLR()
        #lrs = LearningRateScheduler(step_decay)
        callbacks = [mcp, lrp, decay]
        # return all params
        return generator, model, loss, optimizer, callbacks
    def loadModelFromModel(self, model_path, custom_objects=None):
        self.model = load_model(model_path, custom_objects)

    def predict(self, X):
        # call encoder/decoder here
        encoded = self.encoder.encode(X)
        results = self.model.predict(X)
        results = self.encoder.decode(results)
        return results


if __name__ == "__main__":
    model_path = '/Users/maximechoulika/Documents/AlphaPilot/route_planner/ftpilot/graph/Talos_new_newnorm2_mse_1.0/model.005.h5'

    # Dirty fix
    compute = CustomLoss().compute
    pm = SupervisedPredict("predict")
    pm.loadModelFromModel(model_path, custom_objects={'compute': compute})

    data_path = "../resources/data_killian.pkl"
    with open(data_path, "rb") as f:
        pm.gt = cPickle.load(f)

    groundt = []
    predict = []
    for k, v in pm.gt.data.items():
        for i in range(len(v)):
            # Lag calculation
            i_o = i + nb_steplag if len(v) < i + nb_steplag else i
            y_in = v[i_o][1]  # c'est la groundthruth
            # Prediction
Beispiel #4
0
 def get_policy_model(self):
     compute = CustomLoss().compute
     model_predict = load_model('/home/bleu/Documents/alphapilot/AlphaPilot/route_planner/ftpilot/graph/100_lambda_all_v2/model.020.h5', custom_objects={'compute': compute})
     model_predict.summary()
     return model_predict
 def __getPolicyModel(self, model_path):
     """ Load last model, using our 'compute' custom loss. """
     compute = CustomLoss().compute
     model = load_model(model_path, custom_objects={"compute": compute})
     model.summary()
     return model