def create_keras_model_dense():
    mc = MeasureCollection()
    m = Measurement(1, 1111111111, 48, 14, 4,
                    GroundTruth(1111, GroundTruthClass.FREE_SPACE))
    mc.add_measure(m)
    dataset = DataSet.get_raw_sensor_dataset([mc])
    model = Sequential()
    model.add(Dense(64, activation='relu', input_dim=len(dataset.x[0])))
    model.add(Dropout(0.1))
    model.add(Dense(64, activation='relu'))
    model.add(Dropout(0.1))
    model.add(Dense(64, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(64, activation='relu'))
    model.add(Dropout(0.1))
    model.add(Dense(64, activation='relu'))
    model.add(Dropout(0.1))
    model.add(Dense(len(dataset.class_labels), activation='softmax'))

    sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
    model.compile(loss='categorical_crossentropy',
                  optimizer='adam',
                  metrics=['accuracy'])

    return model
Beispiel #2
0
    def read_from_file(path):
        with open(path, 'r') as file_to_read_from:
            csv_reader = csv.reader(file_to_read_from, delimiter=',')
            measure_collections = []
            last_id = None
            measure_collection = None
            for row in csv_reader:
                if len(row) > 0:
                    cur_id = row[0]
                    if last_id is None or last_id != cur_id:
                        if measure_collection is not None:
                            measure_collections.append(measure_collection)
                        measure_collection = MeasureCollection()

                    measure_collection.add_measure(
                        Measurement(
                            float(row[1]), float(row[2]), float(row[3]),
                            float(row[4]),
                            GroundTruth(float(row[2]), row[5] == 'True',
                                        row[6] == 'True')))
                    last_id = cur_id

        return measure_collections
    def read(file_path, ground_truth_path, options=None):
        if options is None:
            options = dict()

        replacement_values = options.get('replacement_values', {})
        min_value = options.get('min_measurement_value', 0.0)
        max_measure_value = options.get('max_measure_value', 1000.0)

        gps_measurements = []
        distances = []

        with open(file_path, 'r') as captured_file:
            csv_reader = csv.reader(captured_file, delimiter=',')
            i = 0
            last_gps_i = None
            for row in csv_reader:
                sensor_type = row[0]
                timestamp = float(row[1])
                if sensor_type == 'LidarLite':
                    distance_value = float(row[2]) / 100
                    if distance_value >= min_value:
                        distance_value = replacement_values.get(
                            distance_value, distance_value)
                        if distance_value > max_measure_value:
                            distance_value = max_measure_value
                        distances.append(
                            LidarLiteMeasurement(timestamp, distance_value))
                elif sensor_type == 'GPS':
                    if row[2] != '0.0' and row[3] != '0.0' and \
                            row[2] != 'nan' and row[3] != 'nan' and \
                            (last_gps_i is None or (i - last_gps_i) < 3):
                        gps_measurements.append(
                            GPSMeasurement(timestamp, float(row[2]),
                                           float(row[3]), float(row[4])))
                    last_gps_i = i
                else:
                    print('unknown sensor', sensor_type)
                i += 1

        print('read gps measures', len(gps_measurements))
        print('read distance measures', len(distances))

        ground_truth = []
        if ground_truth_path is not None:
            ground_truth = GroundTruth.read_from_file(ground_truth_path)

        distance_index = 0
        while gps_measurements[0].timestamp > distances[
                distance_index].timestamp:
            distance_index += 1
        gps_index = 0

        measurements = []
        while gps_index < len(gps_measurements) - 1:
            g = gps_measurements[gps_index]
            next_g = gps_measurements[gps_index + 1]

            while distance_index < len(
                    distances
            ) and next_g.timestamp > distances[distance_index].timestamp:
                gps = g.get_interpolation(next_g,
                                          distances[distance_index].timestamp)
                measurements.append(
                    Measurement(distances[distance_index].distance,
                                distances[distance_index].timestamp,
                                gps.latitude, gps.longitude, gps.speed, None))
                distance_index += 1

            gps_index += 1

        print('interpolated gps measurements', len(measurements))

        if ground_truth_path is not None:
            measure_index = 0
            ground_truth_index = 0
            while measurements[0].timestamp < ground_truth[0].timestamp:
                measurements.pop(0)

            while ground_truth_index < len(ground_truth):
                gt = ground_truth[ground_truth_index]
                while measure_index < len(measurements) and measurements[
                        measure_index].timestamp < gt.timestamp:
                    measurements[measure_index].ground_truth = gt
                    measure_index += 1

                ground_truth_index += 1

            while measure_index < len(measurements):
                measurements.pop(len(measurements) - 1)

            print('added ground truth', len(measurements))

        print(
            'seconds of measurement',
            measurements[len(measurements) - 1].timestamp -
            measurements[0].timestamp)

        outlier_threshold_distance = options.get('outlier_threshold_distance')
        outlier_threshold_diff = options.get('outlier_threshold_diff')
        if outlier_threshold_distance is not None:
            measurements = Measurement.remove_outliers(
                measurements, outlier_threshold_distance,
                outlier_threshold_diff)

        return measurements
    def on_stop_here(self, instance):
        GroundTruth.write_to_file(
            os.path.join(self.base_path, '00gt' + str(time.time()) + '.dat'),
            self.ground_truth)

        App.get_running_app().stop()
    def on_free_space_clicked(self, instance):
        timestamp = self.get_timestamp(self.cur_index)

        gt = GroundTruth(timestamp, GroundTruthClass.FREE_SPACE)
        self.add_ground_truth(gt)
        self.on_next_clicked('')
    def on_overtaken_motorcycle_clicked(self, instance):
        timestamp = self.get_timestamp(self.cur_index)

        gt = GroundTruth(timestamp, GroundTruthClass.OVERTAKEN_MOTORCYCLE)
        self.add_ground_truth(gt)
        self.on_next_clicked('')
    def on_overtaken_car_clicked(self, instance):
        timestamp = self.get_timestamp(self.cur_index)

        gt = GroundTruth(timestamp, GroundTruthClass.OVERTAKEN_CAR)
        self.add_ground_truth(gt)
        self.on_next_clicked('')
    def on_parking_bicycle_clicked(self, instance):
        timestamp = self.get_timestamp(self.cur_index)

        gt = GroundTruth(timestamp, GroundTruthClass.PARKING_BICYCLE)
        self.add_ground_truth(gt)
        self.on_next_clicked('')
    def on_other_parking_car_clicked(self, instance):
        timestamp = self.get_timestamp(self.cur_index)

        gt = GroundTruth(timestamp, GroundTruthClass.OTHER_PARKING_CAR)
        self.add_ground_truth(gt)
        self.on_next_clicked('')