Пример #1
0
def main(batch_size=64,
         max_epochs=100,
         validation_split=0.2,
         early_stop=EarlyStopping()):
    model_hdf5_path = "./hdf5s/"

    if args.dataset == 'taxi':
        sampler = file_loader.file_loader()
    elif args.dataset == 'bike':
        sampler = file_loader.file_loader(config_path="data_bike.json")
    else:
        raise Exception("Can not recognize dataset, please enter taxi or bike")
    modeler = models.models()

    if args.model_name == "stdn":
        # training
        att_cnnx, att_flow, att_x, cnnx, flow, x, y = sampler.sample_stdn(datatype="train",
                                                                          att_lstm_num=args.att_lstm_num, \
                                                                          long_term_lstm_seq_len=args.long_term_lstm_seq_len,
                                                                          short_term_lstm_seq_len=args.short_term_lstm_seq_len, \
                                                                          nbhd_size=args.nbhd_size,
                                                                          cnn_nbhd_size=args.cnn_nbhd_size)

        print(("Start training {0} with input shape {2} / {1}".format(
            args.model_name, x.shape, cnnx[0].shape)))

        model = modeler.stdn(att_lstm_num=args.att_lstm_num,
                             att_lstm_seq_len=args.long_term_lstm_seq_len, \
                             lstm_seq_len=len(cnnx), feature_vec_len=x.shape[-1], \
                             cnn_flat_size=args.cnn_flat_size, nbhd_size=cnnx[0].shape[1],
                             nbhd_type=cnnx[0].shape[-1])

        model.fit( \
            x=att_cnnx + att_flow + att_x + cnnx + flow + [x, ], \
            y=y, \
            batch_size=batch_size, validation_split=validation_split, epochs=max_epochs,
            callbacks=[early_stop])

        att_cnnx, att_flow, att_x, cnnx, flow, x, y = sampler.sample_stdn(
            datatype="test",
            nbhd_size=args.nbhd_size,
            cnn_nbhd_size=args.cnn_nbhd_size)
        y_pred = model.predict( \
            x=att_cnnx + att_flow + att_x + cnnx + flow + [x, ], )
        threshold = float(
            sampler.threshold) / sampler.config["volume_train_max"]
        print(("Evaluating threshold: {0}.".format(threshold)))
        (prmse, pmape), (drmse, dmape) = eval_lstm(y, y_pred, threshold)
        print((
            "Test on model {0}:\npickup rmse = {1}, pickup mape = {2}%\ndropoff rmse = {3}, dropoff mape = {4}%"
            .format(args.model_name, prmse, pmape * 100, drmse, dmape * 100)))

        currTime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        model.save(model_hdf5_path + args.model_name + currTime + ".hdf5")
        return

    else:
        print("Cannot recognize parameter...")
        return
Пример #2
0
def main(att_lstm_num = 3, long_term_lstm_seq_len = 3, short_term_lstm_seq_len = 7, cnn_nbhd_size = 3, nbhd_size = 2, cnn_flat_size = 128,\
     batch_size = 64, max_epochs = 100, validation_split = 0.2, early_stop = EarlyStopping()):
    model_hdf5_path = "./hdf5s/"

    model_name = ""
    if len(sys.argv) == 1:
        print("no parameters")
        return
    else:
        model_name = sys.argv[1]

    sampler = file_loader.file_loader()
    modeler = models.models()

    if model_name[2:] == "stdn":
        #training
        att_cnnx, att_flow, att_x, cnnx, flow, x, y = sampler.sample_stdn(datatype = "train", att_lstm_num = att_lstm_num,\
        long_term_lstm_seq_len = long_term_lstm_seq_len, short_term_lstm_seq_len = short_term_lstm_seq_len,\
        nbhd_size = nbhd_size, cnn_nbhd_size = cnn_nbhd_size)

        print("Start training {0} with input shape {2} / {1}".format(
            model_name[2:], x.shape, cnnx[0].shape))

        model = modeler.stdn(att_lstm_num = att_lstm_num, att_lstm_seq_len = long_term_lstm_seq_len,\
        lstm_seq_len = len(cnnx), feature_vec_len = x.shape[-1],\
        cnn_flat_size = cnn_flat_size, nbhd_size = cnnx[0].shape[1], nbhd_type = cnnx[0].shape[-1])


        model.fit(\
        x = att_cnnx + att_flow + att_x + cnnx + flow + [x,],\
        y = y,\
        batch_size=batch_size, validation_split = validation_split, epochs=max_epochs, callbacks=[early_stop])

        att_cnnx, att_flow, att_x, cnnx, flow, x, y = sampler.sample_stdn(
            datatype="test", nbhd_size=nbhd_size, cnn_nbhd_size=cnn_nbhd_size)
        y_pred = model.predict(\
        x = att_cnnx + att_flow + att_x + cnnx + flow + [x,],)
        threshold = float(
            sampler.threshold) / sampler.config["volume_train_max"]
        print("Evaluating threshold: {0}.".format(threshold))
        (prmse, pmape), (drmse, dmape) = eval_lstm(y, y_pred, threshold)
        print(
            "Test on model {0}:\npickup rmse = {1}, pickup mape = {2}%\ndropoff rmse = {3}, dropoff mape = {4}%"
            .format(model_name[2:], prmse, pmape * 100, drmse, dmape * 100))

        currTime = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
        model.save(model_hdf5_path + model_name[2:] + currTime + ".hdf5")
        return

    print("Cannot recognize parameter...")
    return
Пример #3
0
 def klikniecie(self):
     otworz_plik = QFileDialog.getOpenFileName(self, 'Open file', '',
                                               "Object files (*.obj)")
     self.widget_modelu.wstaw_obiekt(file_loader(otworz_plik[0]))
     self.widget_modelu.update()
Пример #4
0
    def button_powierzchnia(self):
        self.widget_modelu.rysuj_powierzchnie = self.eliminacja_powierzchni_CB.isChecked(
        )
        self.widget_modelu.update()

    def retranslateUi(self):
        _translate = QtCore.QCoreApplication.translate
        self.setWindowTitle(_translate("MainWindow", "Prezentacja Modelu 3D"))
        self.label_pozycja_kamery.setText(
            _translate("MainWindow", "Przesunięcie"))
        self.label_kierunek_patrzenia.setText(_translate(
            "MainWindow", "Obrót"))
        self.eliminacja_powierzchni_CB.setText(
            _translate("MainWindow", "Eliminacja Powierzchni \n"
                       "zasłoniętych"))
        self.label_rotate.setText(_translate("MainWindow", "rotate"))
        self.button_wczytaj_obiekt.setText(
            _translate("MainWindow", "Wczytaj Obiekt"))


if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)
    okno = Ui_MainWindow()
    okno.setupUi()
    okno.widget_modelu.wstaw_obiekt(
        file_loader("low-poly-fox-by-pixelmannen.obj"))
    okno.widget_modelu.przesun(0, 0, 0)
    okno.widget_modelu.obroc(0, 0, 0)
    sys.exit(app.exec_())