Beispiel #1
0
def test_model(dataset: dataset_json.Dataset, input_components, model_path):
    model = architectures.safe_load_model(model_path, compile=False)
    # architectures.apply_predict_decorator(model)

    host = "127.0.0.1"
    port = 9091

    window = windowInterface()  # create a window

    config = {
        "host": host,
        "port": port,
        "window": window,
        "use_speed": (True, True),
        "sleep_time": 0.01,
        "PID_settings": [17, 0.5, 0.3, 1.0, 1.0],
        "loop_settings": [True, False, False, True, False, False],
        "buffer_time": 11,
        "track": "warren",
        "model": model,
        "dataset": dataset,
        "input_components": input_components,
    }

    universal_client(config, True, "model_test")
    window.mainloop()
Beispiel #2
0
from custom_modules.datasets import dataset_json
from custom_modules.vis import vis_fe, vis_lab

physical_devices = tensorflow.config.list_physical_devices("GPU")
for gpu_instance in physical_devices:
    tensorflow.config.experimental.set_memory_growth(gpu_instance, True)

base_path = os.path.expanduser("~") + "\\random_data"
dos = f"{base_path}\\donkeycar\\20-11-21\\"
Dataset = dataset_json.Dataset(["direction", "speed", "throttle"])
input_components = []

gdos = Dataset.load_dataset_sorted(dos, flat=True)
np.random.shuffle(gdos)

model = architectures.safe_load_model("test_model\\models\\maxpool_renault.h5", compile=True)
# architectures.apply_predict_decorator(model)
model.summary()

vis_model = tensorflow.keras.models.Model(model.inputs, model.layers[-1].output)

for labpath in gdos:
    img, annotation = Dataset.load_img_and_annotation(labpath, to_list=False)

    to_pred = Dataset.make_to_pred_annotations([img], [annotation], input_components)
    prediction_dict, dt = model.predict(to_pred)
    img = img / 255

    for class_idx in range(vis_model.output.shape[1]):
        vis_img = vis_fe.get_gradcam(vis_model, to_pred, class_idx, penultimate_layer=11)
        vis_img = np.transpose(vis_img[0], (1, 2, 0))
Beispiel #3
0
base_path = os.path.expanduser("~") + "\\random_data"
dos = f"{base_path}\\donkey\\"

physical_devices = tensorflow.config.list_physical_devices("GPU")
for gpu_instance in physical_devices:
    tensorflow.config.experimental.set_memory_growth(gpu_instance, True)


Dataset = dataset_json.Dataset(["direction", "speed", "throttle"])
input_components = []

gdos = Dataset.load_dataset(dos, flat=True)
np.random.shuffle(gdos)

model = architectures.safe_load_model("test_model\\models\\test_renault.h5", compile=False)
# architectures.apply_predict_decorator(model)

fe = architectures.get_fe(model)
fe.summary()

filter_indexes = []
for it, layer in enumerate(fe.layers):
    if "activation" in layer.name:
        filter_indexes.append(it)


for labpath in gdos:
    img, annotation = Dataset.load_img_and_annotation(labpath, to_list=False)

    for index in filter_indexes:
Beispiel #4
0
        flip=True,
        augm=True,
        use_earlystop=False,
        use_tensorboard=False,
        use_plateau_lr=False,
        verbose=True,
        epochs=10,
        batch_size=32,
        show_distr=False,
    )

    # print(architectures.get_flops(save_path))
    if simTest:
        import sim_client

        sim_client.test_model(Dataset, input_components, save_path)

    else:
        if testdosdir:
            paths = Dataset.load_dataset_sorted(test_path, flat=True)
        else:
            paths = Dataset.load_dos_sorted(test_path)

        model = architectures.safe_load_model(save_path, compile=False)
        pred_function.test_compare_paths(Dataset,
                                         input_components,
                                         model,
                                         paths,
                                         waitkey=1,
                                         apply_decorator=False)
Beispiel #5
0
dos = f"{base_path}\\donkeycar\\11-12-21\\1\\"

physical_devices = tensorflow.config.list_physical_devices("GPU")
for gpu_instance in physical_devices:
    tensorflow.config.experimental.set_memory_growth(gpu_instance, True)

Dataset = dataset_json.Dataset(["direction", "speed", "throttle"])
input_components = []

# model = architectures.safe_load_model(
#     "test_model\\models\\pretrained_1.h5", compile=False)
# architectures.apply_predict_decorator(model)
# model_outputs = architectures.get_model_output_names(model)

model1 = architectures.safe_load_model(
    "test_model\\models\\test2_renault.tflite",
    output_names=["direction", "throttle"])
model2 = architectures.safe_load_model(
    "test_model\\models\\test3_renault.tflite",
    output_names=["direction", "throttle"])

gdos = Dataset.load_dos_sorted(dos)

fig = plt.figure()
# plt.style.use("classic")
ax1 = fig.add_subplot(1, 1, 1)
ax2 = ax1.twinx()
ax3 = ax1.twinx()

###
ax1.clear()
Beispiel #6
0
joy = controller.XboxOneJoystick()
joy.init()
assert joy.connected is True
print("joy working")

# cap = camera.usbWebcam(topcrop=0.2, botcrop=0.0)
cap = cv2.VideoCapture(0)
print("cam working")

basedir = os.path.dirname(os.path.abspath(__file__))

# model = architectures.safe_load_model(f"{basedir}/models/auto_label7.h5", compile=False)

# Load TFLite model
model = architectures.safe_load_model(
    f"{basedir}/../test_model/models/test2_renault.tflite", ["direction"])

# checking if the controller is working properly
joy_leftX = 0
while joy_leftX <= 0.9:
    joy_leftX = joy.axis_states["x"]
    print(joy_leftX, end="\r")
    time.sleep(0.01)

while joy_leftX >= -0.9:
    joy_leftX = joy.axis_states["x"]
    print(joy_leftX, end="\r")
    time.sleep(0.01)

print("Starting mainloop")
Beispiel #7
0
        "loop_settings": [True, False, False, True, False, False],
        "buffer_time": 11,
        "track": "warren",
        "model": model,
        "dataset": dataset,
        "input_components": input_components,
    }

    universal_client(config, True, "model_test")
    window.mainloop()


if __name__ == "__main__":
    model_path = os.getcwd() + os.path.normpath(
        "/test_model/models/test_renault.tflite")
    model = architectures.safe_load_model(model_path,
                                          output_names=["direction"])
    # model.summary()

    dataset = dataset_json.Dataset(["direction", "speed", "throttle", "time"])
    input_components = []

    hosts = ["127.0.0.1", "donkey-sim.roboticist.dev", "sim.diyrobocars.fr"]
    host = hosts[0]
    port = 9091

    window = windowInterface()  # create a window

    config = {
        "host": host,
        "port": port,
        "window": window,
Beispiel #8
0
    def __init__(self, Dataset, model_path):
        self.Dataset = Dataset

        model = architectures.safe_load_model(model_path, compile=False)
        self.fe = architectures.get_flat_fe(model)