This repository was archived by the owner on Jan 7, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathinterface.py
More file actions
111 lines (97 loc) · 3.27 KB
/
interface.py
File metadata and controls
111 lines (97 loc) · 3.27 KB
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
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
from __future__ import absolute_import
class DataIngestionInterface(object):
"""
A data ingestion extension
"""
def __init__(self, is_inference_db=False, **kwargs):
"""
Initialize the data ingestion extension
Parameters:
- is_inference_db: boolean value, indicates whether the database is
created for inference. If this is true then the extension needs to
use the data from the inference form and create a database only for
the test phase (stage == constants.TEST_DB)
- kwargs: dataset form fields
"""
# save all data there - no other fields will be persisted
self.userdata = kwargs
# populate instance from userdata dictionary
for k, v in self.userdata.items():
setattr(self, k, v)
def encode_entry(self, entry):
"""
Encode the entry associated with specified ID (returned by
itemize_entries())
Returns a tuble (feature, label)
Data are expected in HWC format
Color images are expected in RGB order
"""
raise NotImplementedError
@staticmethod
def get_category():
raise NotImplementedError
@staticmethod
def get_dataset_form():
"""
Return a Form object with all fields required to create the dataset
"""
raise NotImplementedError
@staticmethod
def get_dataset_template(form):
"""
Parameters:
- form: form returned by get_dataset_form(). This may be populated
with values if the job was cloned
return:
- (template, context) tuple
- template is a Jinja template to use for rendering dataset creation
options
- context is a dictionary of context variables to use for rendering
the form
"""
raise NotImplementedError
@staticmethod
def get_id():
"""
Return unique ID
"""
raise NotImplementedError
def get_inference_form(self):
"""
Return a Form object with all fields required to create an inference dataset
"""
return None
@staticmethod
def get_inference_template(form):
"""
Parameters:
- form: form returned by get_inference_form().
return:
- (template, context) tuple
- template is a Jinja template to use for rendering the inference form
- context is a dictionary of context variables to use for rendering
the form
"""
return (None, None)
@staticmethod
def get_title():
"""
Return get_title
"""
raise NotImplementedError
def get_user_data(self):
"""
Return serializable user data
The data will be persisted as part of the dataset job data
"""
return self.userdata
def itemize_entries(self, stage):
"""
Return a list of entry IDs to encode
This function is called on the main thread
The returned list will be spread across all reader threads
Reader threads will call encode_entry() with IDs returned by
this function in no particular order
"""
raise NotImplementedError