Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbetti Davide (Student Com16) committed Jan 2, 2022
2 parents 3c5e987 + a663966 commit b55f4be
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 40 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,7 @@ The corrected version of the trace is then exported in the GPX format.

In order to run the application, please follow the subsequent steps:

1) Install the package by executing the following command: `pip install -i https://test.pypi.org/simple/ --extra-index-url https://google-coral.github.io/py-repo/ gpsclean`
2) Now you are ready to clean your first GPS trace by executing the following command: `gpsclean path/to/your_trace.gpx`
3) In the same folder where the original trace resides, you will find a cleaned version of the trace with the suffix "_cleaned"

## Downloading a pre-built all-in-one executable

On the other hand, if you prefer to download a all-in-one executable which does not require any prior software installed (not even Python), you can find pre-built all-in-one packages in the [Release section](https://github.com/sbettid/GPSClean/releases) of the repository.


## How to manually create the all-in-one executable

1) Clone the [repository](https://github.com/sbettid/GPSClean) and open a shell in the `src/gpsclean` folder
2) Execute the following command: `pyinstaller -F --add-data "data/model_42t_traces.h5;data" gpsclean.py`
3) At the end of the process, a dist folder can be found inside the `src/gpsclean` folder, containing the packaged executable.
1) Download the last released package from the [Release section](https://github.com/sbettid/GPSClean/releases) of this repository.
2) Install the downloaded package by executing the following command: `pip install --extra-index-url https://google-coral.github.io/py-repo/ gpsclean-x.y.z-py3-none-any.whl`
3) Now you are ready to clean your first GPS trace by executing the following command: `gpsclean path/to/your_trace.gpx`
4) In the same folder where the original trace resides, you will find a cleaned version of the trace with the suffix "_cleaned"
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="gpsclean",
version="0.3.0",
version="0.4.0",
author="Davide Sbetti",
author_email="[email protected]",
description="An application to correct a GPS trace using machine learning techniques",
Expand Down Expand Up @@ -35,6 +35,7 @@
"scipy>=1.6.1",
"pyproj>=3.0.0",
"numpy>=1.20.0",
"matplotlib>=3.0.0",
],
package_data={
"gpsclean": ["data/*.tflite"],
Expand Down
19 changes: 5 additions & 14 deletions src/gpsclean.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: gpsclean
Version: 0.3.0
Version: 0.4.0
Summary: An application to correct a GPS trace using machine learning techniques
Home-page: https://github.com/sbettid/GPSClean
Author: Davide Sbetti
Expand Down Expand Up @@ -77,18 +77,9 @@ The corrected version of the trace is then exported in the GPX format.

In order to run the application, please follow the subsequent steps:

1) Install the package by executing the following command: `pip install -i https://test.pypi.org/simple/ --extra-index-url https://google-coral.github.io/py-repo/ gpsclean`
2) Now you are ready to clean your first GPS trace by executing the following command: `gpsclean path/to/your_trace.gpx`
3) In the same folder where the original trace resides, you will find a cleaned version of the trace with the suffix "_cleaned"
1) Download the last released package from the [Release section](https://github.com/sbettid/GPSClean/releases) of this repository.
2) Install the downloaded package by executing the following command: `pip install --extra-index-url https://google-coral.github.io/py-repo/ gpsclean-x.y.z-py3-none-any.whl`
3) Now you are ready to clean your first GPS trace by executing the following command: `gpsclean path/to/your_trace.gpx`
4) In the same folder where the original trace resides, you will find a cleaned version of the trace with the suffix "_cleaned"

## Downloading a pre-built all-in-one executable

On the other hand, if you prefer to download a all-in-one executable which does not require any prior software installed (not even Python), you can find pre-built all-in-one packages in the [Release section](https://github.com/sbettid/GPSClean/releases) of the repository.


## How to manually create the all-in-one executable

1) Clone the [repository](https://github.com/sbettid/GPSClean) and open a shell in the `src/gpsclean` folder
2) Execute the following command: `pyinstaller -F --add-data "data/model_42t_traces.h5;data" gpsclean.py`
3) At the end of the process, a dist folder can be found inside the `src/gpsclean` folder, containing the packaged executable.

1 change: 1 addition & 0 deletions src/gpsclean.egg-info/requires.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pandas>=0.25.3
scipy>=1.6.1
pyproj>=3.0.0
numpy>=1.20.0
matplotlib>=3.0.0
14 changes: 9 additions & 5 deletions src/gpsclean/FullTraining.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,27 +164,31 @@ def compress_trace_predictions(predictions, indices, n_classes):
#crate the points labels matrix
unique_indices = np.unique(indices.flatten())
points = { key : np.zeros(n_classes) for key in unique_indices}
means = { key : 0 for key in unique_indices}

#loop over predictions and update the correspondent label
for k in range(predictions.shape[0]):
for j in range(predictions.shape[1]):
points[indices[k][j]][predictions[k][j]] += 1
means[indices[k][j]] += predictions[k][j]

#apply majority voting and record multiple classifications for statistics use
for point in points:
#apply majority voting but keep track also of the mean, in case the user wants it as output
for point in points:
means[point] = means[point]/np.sum(points[point])
points[point] = np.argmax(points[point])

#rebuild the trace sorting the points
sorted_keys = sorted(points)

trace_predictions = []
trace_mean_prediction = []

for key in sorted_keys: #the for each point
for key in sorted_keys: #then for each point
if not key == max_int:
trace_predictions.append(points[key]) #we append to the list the final prediction
trace_mean_prediction.append(means[key]) #... and the mean prediction

return np.array(trace_predictions)
return np.array(trace_predictions), np.array(trace_mean_prediction)


def convert_to_ECEF(points):
Expand Down
38 changes: 32 additions & 6 deletions src/gpsclean/gpsclean.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,27 @@
import tflite_runtime.interpreter as tflite
import tflite_runtime
from gpsclean import Correction as tc
from geojson import Feature, LineString, FeatureCollection, dump
from geojson import Feature, LineString, FeatureCollection, Point, dump
import argparse
from argparse import RawTextHelpFormatter
from art import *
import matplotlib

#current version of the program
__VERSION__ = "0.3.0"
__VERSION__ = "0.4.0"

def main():

#add description of the program in the arguments parser
parser=argparse.ArgumentParser(description='Applies a machine learning model to recognise errors in your GPX input trace.\nThe output is represented by the corrected version of your trace, always in the GPX format (Kalman filters are applied on outliers at this stage).\n Optionally, you can have as a second output the original trace with the predicted errors in the GeoJSON format (you can view and inspect it on https://api.dawnets.unibz.it/ ).\nFor more info please visit: https://gitlab.inf.unibz.it/gps-clean/transform-and-model', formatter_class=RawTextHelpFormatter)
parser=argparse.ArgumentParser(description='Applies a machine learning model to recognise errors in your GPX input trace.\nThe output is represented by the corrected version of your trace, always in the GPX format (Kalman filters are applied on outliers at this stage).\nOptionally, you can have as a second output the original trace with the predicted errors in the GeoJSON format (you can view and inspect it on https://api.dawnets.unibz.it/ ).\nMoreover, a third option is to have the mean of the predictions for each point as output, represented by a continuous color (correct = green, pause = yellow, outlier = red, indoor = gray). The output GeoJSON can be visually inspected at: https://geojson.io. \n\nFor more info please visit: https://gitlab.inf.unibz.it/gps-clean/transform-and-model', formatter_class=RawTextHelpFormatter)

#add argument: input trace in GPX format (mandatory)
parser.add_argument("input_trace",help="Your input GPS trace in the GPX format. Example: gps_trace.gpx")

#add argument: boolean to output also the predictions (optional)
parser.add_argument("-op","--outputPredictions",help="Output predicted points in a GeoJSON file", action="store_true")
parser.add_argument("-op","--outputPredictions",help="Output predicted points in a GeoJSON file (_predicted)", action="store_true")
#add argument: boolean to output also the mean predictions colored (optional)
parser.add_argument("-mpc","--meanPredictionColored",help="Output the mean prediction of each point with its continuous color (correct = green, pause = yellow, outlier = red, indoor = gray) in a GeoJSON file (_predictedColors)", action="store_true")
#add argument: integer to represent the chosen R parameters for the measurement nois (optional)
parser.add_argument("-r","--RMeasurementNoise",type=float, default=4.9, help="R parameter representing the measurement noise for the Kalman Filter")
#add argument: print program version and exit
Expand Down Expand Up @@ -74,10 +77,11 @@ def main():
segments, indices, predictions = ft.predict_trace(interpreter, deltas, 15, 2)

#compress the predictions obtaining a point to point prediction
pred_points = ft.compress_trace_predictions(predictions, indices, 4)
pred_points, mean_pred_points = ft.compress_trace_predictions(predictions, indices, 4)

#insert prediction for starting point, assumed to be correct
full_pred_points=np.insert(pred_points, 0, 0)
full_mean_pred_points=np.insert(mean_pred_points, 0, 0)

#remove the pauses
reduced_points, reduced_times, reduced_delta, reduced_predictions, original_trace, original_times = tc.remove_pauses(points[:,:3], times, full_pred_points, None)
Expand Down Expand Up @@ -167,6 +171,28 @@ def main():
#write on file
with open(filename + "_predicted.geojson", 'w') as f:
dump(feature_collection, f)


#check if we need to output also the mean colored predictions
if args.meanPredictionColored:
print("Exporting also mean predictions colored...")
colorMap = matplotlib.colors.LinearSegmentedColormap.from_list('my_colormap', ['green', 'yellow', 'red', 'gray'])
norm = matplotlib.colors.Normalize(vmin=0, vmax=3)
mappable = matplotlib.cm.ScalarMappable(norm=norm, cmap=colorMap)

features = []
for i in range(points.shape[0]):
cur_point = Point((points[i][0], points[i][1], points[i][2]))
rgba = mappable.to_rgba(full_mean_pred_points[i])
color = matplotlib.colors.rgb2hex(rgba)
cur_properties = {'marker-color': color, 'marker-size': 'small', 'meanPrediction': float(full_mean_pred_points[i]), 'prediction': int(full_pred_points[i]), 'id': int(i)}
cur_feature = Feature(geometry = cur_point, properties = cur_properties)
features.append(cur_feature)

feature_collection = FeatureCollection(features)

#write on file
with open(filename + "_predictedColors.geojson", 'w') as f:
dump(feature_collection, f)

if __name__ == '__main__':
main()

0 comments on commit b55f4be

Please sign in to comment.