This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/Microsoft/arcticseals
- Loading branch information
Showing
13 changed files
with
163 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,43 @@ | ||
## Hotspot Classifier based on Random Forest Classifier | ||
|
||
Will be filled in in next commit | ||
This folder contains the code for training and applying a random forest classifier in sci-kit learn to the arcticseal data. The classifier uses Sci-Kit Learn's classifier class so they can easily be switched out to test other classifiers. We are also using PCA to project the raw data onto "eigen-seals" like the following table: | ||
|Eigen Seal 1 | Eigen Seal 2| | ||
|------------ | ------------| | ||
|![alt text](./images/eigenseal1.png "Eigen-Seal 1") | ![alt text](./images/eigenseal2.png "Eigen-Seal 2")| | ||
|
||
## Classifying | ||
The classification script supports two modes for processing images: command line and as a library import to another script. | ||
|
||
#### Launch Classifier from the Command line | ||
The script requires three flags from the command line with an optional fourth: | ||
1. `--datadir` the path to the directory where the thermal images are stored | ||
1. `--datafile` the path to the csv file that you want to process | ||
1. `--modelfile` the path to the pickled version of the classifier (output by hotspot_training.py) | ||
1. `--outfile` (optional) the path where the csv with classification information should be written. Defaults to `./output.csv` | ||
|
||
The classified CSV file will have the column `hotspot_type` filled in with either "Anamoly" or "Animal" depending on the classification. It will also fill in the column `ir_confidence` that contains the confidence that the classifier has in its decision. | ||
|
||
An example of running the script is shown below: | ||
```bash | ||
python hotspot_classifier.py --datadir ./ArcticSealsData01_Thermal_N/ --datafile ../arcticseals/data/test.csv --modelfile pca_rfc_model_20180725_154906.p | ||
``` | ||
|
||
#### Use Classifier as a Import | ||
The main function for classifying is called `classify_data` and takes the same input values that are passed from the command line as arguments. The function definition and doc string are shown here for convenience: | ||
```python | ||
def classify_data(data_file, data_directory, model_file, output_file): | ||
"""Data loading, classifying and output logic. For compatibility with library inputs | ||
Inputs: | ||
data_file: string, path to the input csv file | ||
data_directory: string, path to the thermal images | ||
model_file: string, path to the classifier model | ||
output_file: string, path to the output csv file | ||
""" | ||
``` | ||
|
||
## File Description | ||
* hotspot_classifier.py: Function for applying the model to a new set of data | ||
* hotspot_training.py: Script for training the model | ||
* pca_rfc_model_20180725_154906.p: Pre-trained model on arcticseals/data/train.csv | ||
* requirements.txt: pip compatible file listing the required dependencies. Install using `pip install requirements.txt` | ||
* README.md: this file |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
Filter: | ||
</button> | ||
<div class="dropdown-menu"> | ||
<a class="dropdown-item" ng-click="filterMe('Anomaly')">Anomaly</a> | ||
<a class="dropdown-item" ng-click="filterMe('Animal')">Animal</a> | ||
</div> | ||
|
||
<div class="row"> | ||
<div ng-repeat="item in items"> | ||
<img src="{{item.color}}"></img> | ||
<img src="{{item.thermal}}"></img><br/> | ||
</div> | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict'; | ||
|
||
var app = angular.module('myApp.view4', ['ngRoute']) | ||
var artic, items; | ||
var getName = function(articI) { | ||
var names = articI.filt_color.split("."); | ||
var name = names[0] + "." + names[1] + "_HOTSPOT_" + articI.hotspot_id + ".JPG"; | ||
return name; | ||
}; | ||
|
||
app.config(['$routeProvider', function($routeProvider) { | ||
$routeProvider.when('/view4', { | ||
templateUrl: 'view4/view4.html', | ||
controller: 'View4Ctrl' | ||
}); | ||
}]) | ||
|
||
app.controller('View4Ctrl', function($scope) { | ||
$scope.items = []; | ||
|
||
var json = null; | ||
|
||
$.getJSON( "/data/training.json", function( data ) { | ||
if (data.Artic !== 'undefined') { | ||
var artic = data.Artic; | ||
var len = artic.length / 2; | ||
for(var i = 0; i < len; i++) { | ||
var articI = artic[i]; | ||
$scope.items.push({"idx": i, "color": "thumb-img//" + articI.filt_color, "thermal" : "thumb-thermal//" + articI.filt_thermal8}); | ||
} | ||
$scope.$apply(); | ||
} | ||
}); | ||
|
||
$scope.filterMe = function( hotspot_type ) { | ||
if (artic !== 'undefined') { | ||
$scope.items = []; | ||
var len = artic.length / 3; | ||
for(var i = 0; i < len; i++) { | ||
var name = getName(artic[i]); | ||
if (artic[i].hotspot_type === hotspot_type) { | ||
$scope.items.push({"idx": i, "file": "crop-img//" + name}); | ||
} | ||
} | ||
items = $scope.items; | ||
$scope.$apply(); | ||
} | ||
}; | ||
|
||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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