예제 #1
0
 def links():
     if random.randrange(0, 3) == 1:
         PressKey(W)
     else:
         ReleaseKey(W)
     PressKey(A)
     ReleaseKey(D)
     ReleaseKey(S)
예제 #2
0
 def nichts():
     if random.randrange(0, 3) == 1:
         PressKey(W)
     else:
         ReleaseKey(W)
     ReleaseKey(A)
     ReleaseKey(D)
     ReleaseKey(S)
예제 #3
0
 def geradeaus_links():
     PressKey(W)
     PressKey(A)
     ReleaseKey(D)
     ReleaseKey(S)
예제 #4
0
 def zurücksetzen():
     PressKey(S)
     ReleaseKey(W)
     ReleaseKey(A)
     ReleaseKey(D)
예제 #5
0
 def geradeaus():
     PressKey(W)
     ReleaseKey(A)
     ReleaseKey(D)
     ReleaseKey(S)
예제 #6
0
def run(width, height, learning_rate, epochs):
    for i in range(1, 10):
        check_model = "car-{}-{}-{}.model".format(str(i), str(learning_rate),
                                                  str(epochs))
        if os.path.isfile(check_model):
            print("Model existiert bereits: " + str(check_model))
        else:
            model_name = "car-{}-{}-{}.model".format(str(i),
                                                     str(learning_rate),
                                                     str(epochs))
            return model_name
    nn_width = int(width) / 2
    nn_height = int(height) / 2
    t_time = 0.09

    def geradeaus():
        PressKey(W)
        ReleaseKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    def links():
        if random.randrange(0, 3) == 1:
            PressKey(W)
        else:
            ReleaseKey(W)
        PressKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    def rechts():
        if random.randrange(0, 3) == 1:
            PressKey(W)
        else:
            ReleaseKey(W)
        PressKey(D)
        ReleaseKey(A)
        ReleaseKey(S)

    def zurücksetzen():
        PressKey(S)
        ReleaseKey(W)
        ReleaseKey(A)
        ReleaseKey(D)

    def geradeaus_links():
        PressKey(W)
        PressKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    def geradeaus_rechts():
        PressKey(W)
        PressKey(D)
        ReleaseKey(A)
        ReleaseKey(S)

    def zurücksetzen_links():
        PressKey(S)
        PressKey(A)
        ReleaseKey(W)
        ReleaseKey(D)

    def zurücksetzen_rechts():
        PressKey(S)
        PressKey(D)
        ReleaseKey(W)
        ReleaseKey(A)

    def nichts():
        if random.randrange(0, 3) == 1:
            PressKey(W)
        else:
            ReleaseKey(W)
        ReleaseKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    model = alexnet(int(nn_width), int(nn_height), float(learning_rate))
    model.load(model_name)

    for i in list(range(6))[::-1]:
        print(i + 1)
        time.sleep(1)

    paused = False

    while True:
        if not paused:
            bild = bild_erfassen(region=(0, 30, int(width), int(height) + 26))
            bild = cv2.cvtColor(bild, cv2.COLOR_BGR2RGB)
            nn_width = int(width) / 2
            nn_height = int(height) / 2
            bild = cv2.resize(bild, (int(nn_width), int(nn_height)))

            vorhersage = model.predict(
                [bild.reshape(int(nn_width), int(nn_height), 3)])[0]
            vorhersage = np.array(vorhersage) * np.array(
                [4.5, 0.1, 0.1, 0.1, 1.8, 1.8, 0.5, 0.5, 0.2])
            print(vorhersage)
            auswahl = np.argmax(vorhersage)

            if auswahl == 0:
                geradeaus()
                auswahl_getroffen = "Geradeaus"
            elif auswahl == 1:
                zurücksetzen()
                auswahl_getroffen = "Zurücksetzen"
            elif auswahl == 2:
                links()
                auswahl_getroffen = "Links"
            elif auswahl == 3:
                rechts()
                auswahl_getroffen = "Rechts"
            elif auswahl == 4:
                geradeaus_links()
                auswahl_getroffen = "Geradeaus + Links"
            elif auswahl == 5:
                geradeaus_rechts()
                auswahl_getroffen = "Geradeaus + Rechts"
            elif auswahl == 6:
                zurücksetzen_links()
                auswahl_getroffen = "Zurücksetzen + Links"
            elif auswahl == 7:
                zurücksetzen_rechts()
                auswahl_getroffen = "Zurücksetzen + Rechts"
            elif auswahl == 8:
                nichts()
                auswahl_getroffen = "Nichts"

            print(auswahl_getroffen)

        keys = key_check()

        if 'T' in keys:
            if paused:
                paused = False
                time.sleep(1)
            else:
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                ReleaseKey(S)
                time.sleep(1)
예제 #7
0
def run(width, height, learning_rate, epochs):
    model_id = 1
    nn_width = int(width) / 2
    nn_height = int(height) / 2
    output_size = 9

    model_name = "model{}-{}_lr-{}_epochs".format(str(model_id),
                                                  float(learning_rate),
                                                  str(epochs))

    def geradeaus():
        PressKey(W)
        ReleaseKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    def links():
        if random.randrange(0, 3) == 1:
            PressKey(W)
        else:
            ReleaseKey(W)
        PressKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    def rechts():
        if random.randrange(0, 3) == 1:
            PressKey(W)
        else:
            ReleaseKey(W)
        PressKey(D)
        ReleaseKey(A)
        ReleaseKey(S)

    def zurücksetzen():
        PressKey(S)
        ReleaseKey(W)
        ReleaseKey(A)
        ReleaseKey(D)

    def geradeaus_links():
        PressKey(W)
        PressKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    def geradeaus_rechts():
        PressKey(W)
        PressKey(D)
        ReleaseKey(A)
        ReleaseKey(S)

    def zurücksetzen_links():
        PressKey(S)
        PressKey(A)
        ReleaseKey(W)
        ReleaseKey(D)

    def zurücksetzen_rechts():
        PressKey(S)
        PressKey(D)
        ReleaseKey(W)
        ReleaseKey(A)

    def nichts():
        if random.randrange(0, 4) == 1:
            PressKey(W)
        else:
            ReleaseKey(W)
        ReleaseKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    model = inception3(int(nn_width),
                       int(nn_height),
                       float(learning_rate),
                       output=int(output_size))
    model.load(model_name)

    for i in list(range(6))[::-1]:
        print(i + 1)
        time.sleep(1)

    paused = False

    while True:
        if not paused:
            bild = bild_erfassen(region=(0, 30, int(width), int(height) + 26))
            bild = cv2.cvtColor(bild, cv2.COLOR_BGR2RGB)
            bild = cv2.resize(bild, (int(nn_width), int(nn_height)))
            #cv2.imshow("test", bild)
            #time.sleep(0.09)

            vorhersage = model.predict(
                [bild.reshape(int(nn_width), int(nn_height), 3)])[0]
            vorhersage = np.array(vorhersage) * np.array(
                [0.3, 0.9, 2.8, 2.8, 1.5, 1.5, 0.5, 0.5, 0.7])
            #print(vorhersage)
            auswahl = np.argmax(vorhersage)

            if auswahl == 0:
                geradeaus()
                auswahl_getroffen = "Geradeaus"
            elif auswahl == 1:
                zurücksetzen()
                auswahl_getroffen = "Zurücksetzen"
            elif auswahl == 2:
                links()
                auswahl_getroffen = "Links"
            elif auswahl == 3:
                rechts()
                auswahl_getroffen = "Rechts"
            elif auswahl == 4:
                geradeaus_links()
                auswahl_getroffen = "Geradeaus + Links"
            elif auswahl == 5:
                geradeaus_rechts()
                auswahl_getroffen = "Geradeaus + Rechts"
            elif auswahl == 6:
                zurücksetzen_links()
                auswahl_getroffen = "Zurücksetzen + Links"
            elif auswahl == 7:
                zurücksetzen_rechts()
                auswahl_getroffen = "Zurücksetzen + Rechts"
            elif auswahl == 8:
                nichts()
                auswahl_getroffen = "Nichts"

            print(auswahl_getroffen)

##            if cv2.waitKey(15) & 0xFF == ord("q"):
##                cv2.destroyAllWindows()
##                break

        keys = key_check()

        if 'T' in keys:
            if paused:
                paused = False
                time.sleep(1)
            else:
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                ReleaseKey(S)
                time.sleep(1)
예제 #8
0
 def zurücksetzen_rechts():
     PressKey(S)
     PressKey(D)
     ReleaseKey(W)
     ReleaseKey(A)
예제 #9
0
def rechts():
    PressKey(D)
    PressKey(W)
    ReleaseKey(A)
예제 #10
0
def links():
    PressKey(A)
    PressKey(W)
    ReleaseKey(D)
예제 #11
0
 def chill():
     ReleaseKey(W)
     ReleaseKey(A)
     ReleaseKey(D)
예제 #12
0
 def rechts():
     PressKey(W)
     PressKey(D)
     ReleaseKey(A)
     time.sleep(t_time)
     ReleaseKey(D)
예제 #13
0
 def links():
     PressKey(W)
     PressKey(A)
     ReleaseKey(D)
     time.sleep(t_time)
     ReleaseKey(A)
예제 #14
0
def run(width, height, learning_rate, epochs):
    width = 80
    height = 60
    learning_rate = 1E-3
    epoch = 10
    model_name = "car-{}-{}-{}-epochs.model".format(float(learning_rate),
                                                    "alexnet", int(epochs))

    t_time = 0.09

    def geradeaus():
        PressKey(W)
        ReleaseKey(A)
        ReleaseKey(D)

    def links():
        PressKey(W)
        PressKey(A)
        ReleaseKey(D)
        time.sleep(t_time)
        ReleaseKey(A)

    def rechts():
        PressKey(W)
        PressKey(D)
        ReleaseKey(A)
        time.sleep(t_time)
        ReleaseKey(D)

    def chill():
        ReleaseKey(W)
        ReleaseKey(A)
        ReleaseKey(D)

    model = alexnet(int(width), int(height), float(learning_rate))
    model.load(model_name)

    for i in list(range(6))[::-1]:
        print(i + 1)
        time.sleep(1)

    paused = False

    while True:
        if not paused:
            bild = bild_erfassen(region=(0, 30, 800, 626))
            bild = cv2.cvtColor(bild, cv2.COLOR_BGR2GRAY)
            bild = cv2.resize(bild, (int(width), int(height)))

            vorhersage = model.predict(
                [bild.reshape(int(width), int(height), 1)])[0]
            #moves = list(np.around(vorhersage))
            print(vorhersage)

            turn_thresh = 0.75
            forward_thresh = 0.70

            if vorhersage[1] > forward_thresh:
                geradeaus()
            elif vorhersage[0] > turn_thresh:
                links()
            elif vorhersage[2] > turn_thresh:
                rechts()
            elif vorhersage[0] < 0.1 and vorhersage[1] < 0.1 and vorhersage[
                    2] < 0.1:
                chill()
            else:
                geradeaus()

    ##        if moves == [1, 0, 0]:
    ##            links()
    ##        elif moves == [0, 1, 0]:
    ##            geradeaus()
    ##        elif moves == [0, 0, 1]:
    ##            rechts()

        keys = key_check()

        if 'T' in keys:
            if paused:
                paused = False
                time.sleep(1)
            else:
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                time.sleep(1)
예제 #15
0
def nichts():
    ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
    ReleaseKey(S)
예제 #16
0
 def geradeaus_rechts():
     PressKey(W)
     PressKey(D)
     ReleaseKey(A)
     ReleaseKey(S)
예제 #17
0
 def zurücksetzen_links():
     PressKey(S)
     PressKey(A)
     ReleaseKey(W)
     ReleaseKey(D)
예제 #18
0
def langsam():
    ReleaseKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
예제 #19
0
def run(width, height, learning_rate, epochs):
    model_name = "car-{}-{}-{}-epochs.model".format(float(learning_rate),
                                                    "alexnet", int(epochs))
    nn_width = int(width) / 10
    nn_height = int(height) / 10
    t_time = 0.09

    def geradeaus():
        PressKey(W)
        ReleaseKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    def links():
        if random.randrange(0, 3) == 1:
            PressKey(W)
        else:
            ReleaseKey(W)
        PressKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    def rechts():
        if random.randrange(0, 3) == 1:
            PressKey(W)
        else:
            ReleaseKey(W)
        PressKey(D)
        ReleaseKey(A)
        ReleaseKey(S)

    def zurücksetzen():
        PressKey(S)
        ReleaseKey(W)
        ReleaseKey(A)
        ReleaseKey(D)

    def geradeaus_links():
        PressKey(W)
        PressKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    def geradeaus_rechts():
        PressKey(W)
        PressKey(D)
        ReleaseKey(A)
        ReleaseKey(S)

    def zurücksetzen_links():
        PressKey(S)
        PressKey(A)
        ReleaseKey(W)
        ReleaseKey(D)

    def zurücksetzen_rechts():
        PressKey(S)
        PressKey(D)
        ReleaseKey(W)
        ReleaseKey(A)

    def nichts():
        if random.randrange(0, 3) == 1:
            PressKey(W)
        else:
            ReleaseKey(W)
        ReleaseKey(A)
        ReleaseKey(D)
        ReleaseKey(S)

    model = alexnet(int(nn_width), int(nn_height), float(learning_rate))
    model.load(model_name)

    for i in list(range(6))[::-1]:
        print(i + 1)
        time.sleep(1)

    paused = False

    while True:
        if not paused:
            bild = bild_erfassen(region=(0, 30, int(width), int(height) + 26))
            bild = cv2.cvtColor(bild, cv2.COLOR_BGR2GRAY)
            nn_width = int(width) / 10
            nn_height = int(height) / 10
            bild = cv2.resize(bild, (int(nn_width), int(nn_height)))

            vorhersage = model.predict(
                [bild.reshape(int(nn_width), int(nn_height), 1)])[0]
            vorhersage = np.array(vorhersage)
            print(vorhersage)
            auswahl = np.argmax(vorhersage)

            if auswahl == 0:
                geradeaus()
                auswahl_getroffen = "Geradeaus"
            elif auswahl == 1:
                zurücksetzen()
                auswahl_getroffen = "Zurücksetzen"
            elif auswahl == 2:
                links()
                auswahl_getroffen = "Links"
            elif auswahl == 3:
                rechts()
                auswahl_getroffen = "Rechts"
            elif auswahl == 4:
                geradeaus_links()
                auswahl_getroffen = "Geradeaus + Links"
            elif auswahl == 5:
                geradeaus_rechts()
                auswahl_getroffen = "Geradeaus + Rechts"
            elif auswahl == 6:
                zurücksetzen_links()
                auswahl_getroffen = "Zurücksetzen + Links"
            elif auswahl == 7:
                zurücksetzen_rechts()
                auswahl_getroffen = "Zurücksetzen + Rechts"
            elif auswahl == 8:
                nichts()
                auswahl_getroffen = "Nichts"

            print(auswahl_getroffen)

        keys = key_check()

        if 'T' in keys:
            if paused:
                paused = False
                time.sleep(1)
            else:
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                ReleaseKey(S)
                time.sleep(1)
예제 #20
0
            geradeaus()
        elif vorhersage[0] > turn_thresh:
            links()
        elif vorhersage[2] > turn_thresh:
            rechts()
        elif vorhersage[0] < 0.1 and vorhersage[1] < 0.1 and vorhersage[
                2] < 0.1:
            chill()
        else:
            geradeaus()

##        if moves == [1, 0, 0]:
##            links()
##        elif moves == [0, 1, 0]:
##            geradeaus()
##        elif moves == [0, 0, 1]:
##            rechts()

    keys = key_check()

    if 'T' in keys:
        if paused:
            paused = False
            time.sleep(1)
        else:
            paused = True
            ReleaseKey(A)
            ReleaseKey(W)
            ReleaseKey(D)
            time.sleep(1)