-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathapispec.ts
More file actions
293 lines (262 loc) · 8.51 KB
/
apispec.ts
File metadata and controls
293 lines (262 loc) · 8.51 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import { provide } from 'vue';
import { AnnotationId, StringKeyObject } from 'vue-media-annotator/BaseAnnotation';
import { GroupData } from 'vue-media-annotator/Group';
import { use } from 'vue-media-annotator/provides';
import { TrackData } from 'vue-media-annotator/track';
import { Attribute } from 'vue-media-annotator/use/AttributeTypes';
import { CustomStyle } from 'vue-media-annotator/StyleManager';
import { AttributeTrackFilter } from 'vue-media-annotator/AttributeTrackFilterControls';
import { ImageEnhancements } from 'vue-media-annotator/use/useImageEnhancements';
type DatasetType = 'image-sequence' | 'video' | 'multi' | 'large-image';
type MultiTrackRecord = Record<string, TrackData>;
type MultiGroupRecord = Record<string, GroupData>;
type SubType = 'stereo' | 'multicam' | null; // Additional type info used for UI display enabled pipelines
type PipelineParamType = | 'bool'
| 'int' | 'positive_int' | 'strictly_positive_int' | 'range_int'
| 'float' | 'positive_float' | 'strictly_positive_float' | 'range_float'
| 'folder' | 'path'
| 'file';
interface AnnotationSchema {
version: number;
tracks: MultiTrackRecord;
groups: MultiGroupRecord;
}
/**
* Variation on AnnotationSchema where annotations are lists
* instead of objects, used for convenience with pagination.
*/
interface AnnotationSchemaList {
version: number;
tracks: TrackData[];
groups: GroupData[];
sets: string[];
}
interface DiveParam {
label: string;
type: PipelineParamType;
type_props?: string[];
key: string;
default: string;
}
interface PipeMetadata {
description?: string;
inputType?: string;
outputType?: string;
diveParams?: DiveParam[];
}
interface PipelineRuntimeParams {
frameRange?: [number, number] | null;
}
interface PipelineParams {
kwiverParams?: Record<string, string>;
runtimeParams?: PipelineRuntimeParams;
}
interface Pipe {
name: string;
pipe: string;
type: string;
metadata?: PipeMetadata;
folderId?: string;
ownerId?: string;
ownerLogin?: string;
}
interface Category {
description: string;
pipes: Pipe[];
}
interface TrainingConfig {
name: string;
description?: string;
}
interface TrainingConfigs {
training: {
configs: TrainingConfig[];
default: string;
};
models: Record<string, {
name: string;
type: string;
path?: string;
folderId?: string;
}>;
}
type Pipelines = Record<string, Category>;
interface SaveDetectionsArgs {
tracks: {
delete: AnnotationId[];
upsert: TrackData[];
};
groups: {
delete: AnnotationId[];
upsert: GroupData[];
};
set?: string;
}
interface SaveAttributeArgs {
delete: string[];
upsert: Attribute[];
}
interface SaveAttributeTrackFilterArgs {
delete: string[];
upsert: AttributeTrackFilter[];
}
interface FrameImage {
url: string;
filename: string;
/** Required for large-image (tiled) datasets; used as itemId for getTiles/getTileURL */
id?: string;
}
export interface MultiCamImportFolderArgs {
datasetName?: string; // Girder parent folder name (required on web)
defaultDisplay: string; // In multicam the default camera to display
/** Display order for cameras (matches sourceList / UI order). */
cameraOrder?: string[];
sourceList: Record<string, {
sourcePath: string;
trackFile: string;
}>; // path/track file per camera
calibrationFile?: string; // NPZ calibation matrix file
type: 'image-sequence' | 'video';
}
export interface MultiCamImportKeywordArgs {
defaultDisplay: string; // In multicam the default camera to display
sourcePath: string; // Base folder used for import, globList will filter folder
globList: Record<string, {
glob: string;
trackFile: string;
}>; // glob pattern for base folder
calibrationFile?: string; // NPZ calibation matrix file
type: 'image-sequence'; // Always image-sequence type for glob matching
}
export type MultiCamImportArgs = MultiCamImportFolderArgs | MultiCamImportKeywordArgs;
interface MultiCamMedia {
cameras: Record<string, {
type: DatasetType;
imageData: FrameImage[];
videoUrl: string;
}>;
defaultDisplay: string; // Default camera for displaying the MultiCamMedia
/** Camera names in display order (import / UI order). */
cameraOrder?: string[];
}
interface MediaImportResponse {
jsonMeta: {
originalImageFiles: string[];
};
globPattern: string;
mediaConvertList: string[];
}
/**
* The parts of metadata a user should be able to modify.
*/
interface DatasetMetaMutable {
customTypeStyling?: Record<string, CustomStyle>;
customGroupStyling?: Record<string, CustomStyle>;
confidenceFilters?: Record<string, number>;
timeFilters?: [number, number] | null;
imageEnhancements?: ImageEnhancements;
attributes?: Readonly<Record<string, Attribute>>;
attributeTrackFilters?: Readonly<Record<string, AttributeTrackFilter>>;
error?: string;
}
const DatasetMetaMutableKeys = ['attributes', 'confidenceFilters', 'timeFilters', 'imageEnhancements', 'customTypeStyling', 'customGroupStyling', 'attributeTrackFilters'];
interface DatasetMeta extends DatasetMetaMutable {
id: Readonly<string>;
imageData: Readonly<FrameImage[]>;
videoUrl: Readonly<string | undefined>;
type: Readonly<DatasetType | 'multi'>;
fps: Readonly<number>; // this will become mutable in the future.
name: Readonly<string>;
createdAt: Readonly<string>;
originalFps?: Readonly<number>;
subType: Readonly<SubType>; // In future this could have stuff like IR/EO
multiCamMedia: Readonly<MultiCamMedia | null>;
}
interface Api {
getPipelineList(): Promise<Pipelines>;
runPipeline(itemId: string, pipeline: Pipe, pipelineParams?: PipelineParams): Promise<unknown>;
deleteTrainedPipeline(pipeline: Pipe): Promise<void>;
exportTrainedPipeline(path: string, pipeline: Pipe): Promise<unknown>;
getTrainingConfigurations(): Promise<TrainingConfigs>;
runTraining(
folderIds: string[],
pipelineName: string,
config: string,
annotatedFramesOnly: boolean,
labelText?: string,
fineTuneModel?: {
name: string;
type: string;
path?: string;
folderId?: string;
},
): Promise<unknown>;
loadMetadata(datasetId: string): Promise<DatasetMeta>;
loadDetections(datasetId: string, revision?: number, set?: string): Promise<AnnotationSchemaList>;
saveDetections(datasetId: string, args: SaveDetectionsArgs): Promise<unknown>;
saveMetadata(datasetId: string, metadata: DatasetMetaMutable): Promise<unknown>;
saveAttributes(datasetId: string, args: SaveAttributeArgs): Promise<unknown>;
saveAttributeTrackFilters(datasetId: string,
args: SaveAttributeTrackFilterArgs): Promise<unknown>;
// Non-Endpoint shared functions
openFromDisk(datasetType: DatasetType | 'bulk' | 'calibration' | 'annotation' | 'text' | 'zip', directory?: boolean):
Promise<{canceled?: boolean; filePaths: string[]; fileList?: File[]; root?: string}>;
/** Desktop: immediate child directory names under a parent folder (multicam subfolder import). */
listImmediateSubfolders?(parentPath: string): Promise<string[]>;
/** Desktop: folder path for image-sequence, or first video file inside the folder for video. */
resolveMulticamCameraSourcePath?(
subfolderPath: string,
mediaType: 'image-sequence' | 'video',
): Promise<string>;
getTiles?(itemId: string, projection?: string): Promise<StringKeyObject>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getTileURL?(itemId: string, x: number, y: number, level: number, query: Record<string, any>):
string;
importAnnotationFile(id: string, path: string, file?: File,
additive?: boolean, additivePrepend?: string, set?: string): Promise<boolean | string[]>;
// Desktop-only calibration persistence functions
getLastCalibration?(): Promise<string | null>;
saveCalibration?(path: string): Promise<{ savedPath: string; updatedDatasetIds: string[] }>;
}
const ApiSymbol = Symbol('api');
/**
* provideApi specifies an implementation of the data persistence interface
* for use in vue-web-common
* @param api an api implementation
*/
function provideApi(api: Api) {
provide(ApiSymbol, api);
}
function useApi() {
return use<Readonly<Api>>(ApiSymbol);
}
export {
provideApi,
useApi,
};
export {
AnnotationSchema,
Api,
DatasetMeta,
DatasetMetaMutable,
DatasetMetaMutableKeys,
DatasetType,
DiveParam,
SubType,
PipelineParamType,
FrameImage,
MultiTrackRecord,
MultiGroupRecord,
Pipe,
PipelineParams,
PipelineRuntimeParams,
PipeMetadata,
Pipelines,
SaveDetectionsArgs,
SaveAttributeArgs,
SaveAttributeTrackFilterArgs,
TrainingConfig,
TrainingConfigs,
MultiCamMedia,
MediaImportResponse,
};