-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
interface.py
140 lines (125 loc) · 4.35 KB
/
interface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
from __future__ import absolute_import
class VisualizationInterface(object):
"""
A visualization extension
"""
def __init__(self, **kwargs):
pass
@staticmethod
def get_config_form():
"""
Return a form to be used to configure visualization options
"""
raise NotImplementedError
@staticmethod
def get_config_template(form):
"""
The config template shows a form with view config options
Parameters:
- form: form returned by get_config_form(). This may be populated
with values if the job was cloned
Returns:
- (template, context) tuple
- template is a Jinja template to use for rendering config options
- context is a dictionary of context variables to use for rendering
the form
"""
raise NotImplementedError
@staticmethod
def get_default_visibility():
"""
Return whether to show extension in GUI (can be overridden through
DIGITS configuration options)
"""
return True
def get_header_template(self):
"""
This returns the content to be rendered at the top of the result
page. This may include a summary of the job as well as utility
functions and scripts to use from "view" templates.
By default this method returns (None, None), an indication that there
is no header to display. This method may be overridden in sub-classes
to show more elaborate content.
Returns:
- (template, context) tuple
- template is a Jinja template to use for rendering the header,
or None if there is no header to display
- context is a dictionary of context variables to use for rendering
the form
"""
return None, None
def get_ng_templates(self):
"""
This returns the angularjs content defining the app and maybe a
large scope controller. By default this method returns None,
an indication that there is no angular header. This method
may be overridden in sub-classes to implement the app and controller.
This header html protion will likely be of the form:
<script>
...
</script>
<div ng-app="my_app">
<div ng-controller="my_controller">
and the footer needs to close any open divs:
</div>
</div>
Returns:
- (header, footer) tuple
- header is the html text defining the angular app and adding the ng-app div,
or None if there is no angular app defined
- footer is the html text closing any open divs from the header
or None if there is no angular app defined
"""
return None, None
@staticmethod
def get_id():
"""
Returns a unique ID
"""
raise NotImplementedError
@staticmethod
def get_title():
"""
Returns a title
"""
raise NotImplementedError
@staticmethod
def get_dirname():
"""
Returns the extension's dirname for building a path to the
extension's static files
"""
raise NotImplementedError
def get_view_template(self, data):
"""
The view template shows the visualization of one inference output.
In the case of multiple inference, this method is called once per
input sample.
Parameters:
- data: the data returned by process_data()
Returns:
- (template, context) tuple
- template is a Jinja template to use for rendering config options
- context is a dictionary of context variables to use for rendering
the form
"""
raise NotImplementedError
def process_data(
self,
input_id,
input_data,
inference_data,
ground_truth=None):
"""
Process one inference output
Parameters:
- input_id: index of input sample
- input_data: input to the network
- inference_data: network output
- ground_truth: Ground truth. Format is application specific.
None if absent.
Returns:
- an object reprensenting the processed data
"""
raise NotImplementedError