Created
February 15, 2018 15:59
-
-
Save TheLoneNut/fb091cb52efc16da49c1d83c18df014d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def identify_traffic(x, database, model): | |
| """ | |
| Implements traffic recognition. | |
| Arguments: | |
| x -- the traffic to identify | |
| database -- database containing recognized traffic encodings | |
| model -- the encoding model | |
| Returns: | |
| min_dist -- the minimum distance between traffic encoding and the encodings from the database | |
| identity -- string, the traffic prediction name | |
| """ | |
| # Compute the target "encoding" for the traffic. | |
| encoding = traffic_to_encoding(x, model) | |
| # Find the closest encoding | |
| min_dist = 100 | |
| identity = 'unknown' | |
| for (name, db_enc) in database.items(): | |
| # Compute L2 distance between the target "encoding" and the current "emb" from the database. | |
| dist = np.linalg.norm(db_enc-encoding) | |
| # If this distance is less than the min_dist, then set min_dist to dist, and identity to name. | |
| if dist < min_dist: | |
| min_dist = dist | |
| identity = name | |
| return min_dist, identity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment