예제 #1
0
class Prediction:
    def __init__(self):
        self.bridge = cv_bridge.CvBridge()
        self.IMG_HEIGHT = 200
        self.IMG_WIDTH = 200
        #self.sub=rospy.Subscriber("/cam_front/raw",Image,self.image_cb)
        self.image = cv2.imread("5.jpg")
        self._session = tf.Session()
        self.model = Sequential([
            Conv2D(16,
                   3,
                   padding='same',
                   activation='relu',
                   input_shape=(self.IMG_HEIGHT, self.IMG_WIDTH, 3)),
            MaxPooling2D(),
            Conv2D(32, 3, padding='same', activation='relu'),
            MaxPooling2D(),
            Conv2D(64, 3, padding='same', activation='relu'),
            MaxPooling2D(),
            Flatten(),
            Dense(512, activation='relu'),
            Dense(1)
        ])
        self.model.compile(
            optimizer='adam',
            loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),
            metrics=['accuracy'])
        # Restore the weights
        self.model.load_weights('./checkpoints/lidar_checkpoint')
        self.model._make_predict_function()
        self.model.summary()
        val = self.model.predict([self.image.reshape(-1, 200, 200, 3)])
        if (val[0][0] > 0):
            print("person")
        else:
            print("car")
예제 #2
0
    # Defining our DQN
    dqn = DQNAgent(
        model=model,
        nb_actions=len(env_player.action_space),
        policy=policy,
        memory=memory,
        nb_steps_warmup=1000,
        gamma=0.5,
        target_model_update=1,
        delta_clip=0.01,
        enable_double_dqn=True,
    )

    dqn.compile(Adam(lr=0.00025), metrics=["mae"])

    model._make_predict_function()

    # Training
    env_player.play_against(
        env_algorithm=dqn_training,
        opponent=opponent,
        env_algorithm_kwargs={
            "dqn": dqn,
            "nb_steps": NB_TRAINING_STEPS
        },
    )
    model.save("model_%d" % NB_TRAINING_STEPS)

    model._make_predict_function()

    # Evaluation