-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue/framemap viewer improvements (#92)
* framemap loads with scroll and displays elements ordered by number of detected frames * fmt * use threshold in ranking
- Loading branch information
1 parent
2dabebf
commit b99b697
Showing
14 changed files
with
8,121 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
folder: "temp/military_vehicles_ambaz" | ||
phase: "analyse" | ||
module: "ranking" | ||
config: | ||
elements_in: | ||
- "youtube/keras_pretrained" |
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,5 @@ | ||
"""The ranking module is an ANALYSER that ranks the output from a keras_pretrained analyser. | ||
""" | ||
from .main import RankingAnalyser as main | ||
|
||
__all__ = ["main"] |
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,5 @@ | ||
- name: "threshold" | ||
required: false | ||
input: "float" | ||
desc: "The minimum score for which a prediction should be counted towards an element's rank" | ||
|
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,73 @@ | ||
from lib.common.analyser import Analyser | ||
|
||
# from lib.common.exceptions import ElementShouldSkipError | ||
from lib.common.etypes import Etype | ||
import os | ||
import json | ||
import operator | ||
import collections | ||
from shutil import copyfile | ||
|
||
|
||
class RankingAnalyser(Analyser): | ||
def get_in_etype(self): | ||
return Etype.Any | ||
|
||
def get_out_etype(self): | ||
return Etype.Any | ||
|
||
def pre_analyse(self, config): | ||
self.thresh = config["threshold"] if "threshold" in config else 0.5 | ||
self.rankingData = {} | ||
self.wkDir = "" | ||
|
||
def analyse_element(self, element, config): | ||
id = element["id"] | ||
src = element["base"] | ||
dest = element["dest"] | ||
|
||
# run once | ||
if self.wkDir == "": | ||
self.wkDir = dest.replace(id, "") | ||
|
||
epath = src + "/" + element["id"] + ".json" | ||
with open(epath, "r") as f: | ||
edata = json.load(f) | ||
|
||
labels = edata["labels"] | ||
for label, preds in labels.items(): | ||
count = len( | ||
[ | ||
idx | ||
for idx, _ in enumerate(preds["frames"]) | ||
if preds["scores"][idx] > self.thresh | ||
] | ||
) | ||
if count > 4: | ||
self.logger(f"{label}: {count}") | ||
if label not in self.rankingData: | ||
self.rankingData[label] = {} | ||
self.rankingData[label][id] = count | ||
|
||
dpath = dest + "/" + element["id"] + ".json" | ||
copyfile(epath, dpath) | ||
self.logger(f"Rankings added for {element['id']}.") | ||
|
||
def post_analyse(self, config, derived_dirs): | ||
ranking = self.dataToRanking() | ||
path = self.wkDir + "all" | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
file = path + "/rankings.json" | ||
self.logger("All rankings aggregated, printed to all/rankings.json") | ||
with open(file, "w") as f: | ||
json.dump(ranking, f) | ||
|
||
def dataToRanking(self): | ||
sortedData = {} | ||
for label, values in self.rankingData.items(): | ||
s_vals = sorted(values.items(), key=operator.itemgetter(1)) | ||
s_vals.reverse() | ||
s_els = [t[0] for t in s_vals] | ||
sortedData[label] = s_els | ||
return sortedData |
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,4 @@ | ||
export default { | ||
label: "candle", | ||
label: 'rifle', | ||
threshold: 0.5 | ||
} |
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
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,5 +1,9 @@ | ||
export default { | ||
FETCH_ELEMENTS_ATTEMPT: 'FETCH_ELEMENTS_ATTEMPT', | ||
FETCH_ELEMENTS: 'FETCH_ELEMENTS', | ||
FETCH_ELEMENTS_ERROR: 'FETCH_ELEMENTS_ERROR' | ||
FETCH_ELEMENTS_ERROR: 'FETCH_ELEMENTS_ERROR', | ||
FETCH_NEXT_ELEMENTS_ATTEMPT: 'FETCH_NEXT_ELEMENTS_ATTEMPT', | ||
FETCH_NEXT_ELEMENTS: 'FETCH_NEXT_ELEMENTS', | ||
FETCH_NEXT_ELEMENTS_ERROR: 'FETCH_NEXT_ELEMENTS_ERROR', | ||
FETCH_RANKING: 'FETCH_RANKING' | ||
} |
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
Oops, something went wrong.