-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.swift
656 lines (516 loc) · 21 KB
/
main.swift
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
// Copyright 2020 The SwiftFusion Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import ArgumentParser
import BeeDataset
import BeeTracking
import PenguinStructures
import PenguinParallelWithFoundation
import PythonKit
import SwiftFusion
import TensorFlow
import Foundation
struct OISTVisualizationTool: ParsableCommand {
static var configuration = CommandConfiguration(
subcommands: [VisualizeTrack.self, ViewFrame.self, RawTrack.self, PpcaTrack.self, NaiveRae.self, TrainRAE.self, NaivePca.self])
}
/// View a frame with bounding boxes
struct ViewFrame: ParsableCommand {
@Option(help: "Location of dataset folder which should contain `frames` and `frames_txt`")
var datasetLocation: String = "./OIST_Data"
@Option(help: "Which frame to show")
var frameId: Int = 0
func run() {
let dataURL = URL(fileURLWithPath: datasetLocation)
print("Viewing \(dataURL) at frame \(frameId)")
let dataset = OISTBeeVideo(directory: dataURL, deferLoadingFrames: true)!
let frameRawId = dataset.frameIds[frameId]
let image = dataset.loadFrame(frameRawId)!
// plot(image, boxes: dataset.labels[frameId].enumerated().map {
// (String($0), $1.location)
// }, margin: 10.0, scale: 0.5).show()
}
}
/// Returns a `[N, h, w, c]` batch of normalized patches from a VOT video, and returns the
/// statistics used to normalize them.
/// - dataset: Bee video dataset object
/// - appearanceModelSize: [H, W]
/// - batchSize: number of batch samples
/// - seed: Allow controlling the random sequence
/// - trainSplit: Controls where in the frames to split between train and test
func makeOISTBatch(dataset: OISTBeeVideo, appearanceModelSize: (Int, Int), batchSize: Int = 300, seed: Int = 42, trainSplit: Int = 250)
-> (normalized: Tensor<Double>, statistics: FrameStatistics)
{
var images: [Tensor<Double>] = []
images.reserveCapacity(batchSize)
var currentFrame: Tensor<Double> = [0]
var currentId: Int = -1
var deterministicEntropy = ARC4RandomNumberGenerator(seed: seed)
for label in dataset.labels[0..<trainSplit].randomSelectionWithoutReplacement(k: 10, using: &deterministicEntropy).lazy.joined().randomSelectionWithoutReplacement(k: batchSize, using: &deterministicEntropy).sorted(by: { $0.frameIndex < $1.frameIndex }) {
if currentId != label.frameIndex {
currentFrame = Tensor<Double>(dataset.loadFrame(label.frameIndex)!)
currentId = label.frameIndex
}
images.append(currentFrame.patch(at: label.location, outputSize: appearanceModelSize))
}
let stacked = Tensor(stacking: images)
let statistics = FrameStatistics(stacked)
return (statistics.normalized(stacked), statistics)
}
/// Tracking with a raw l2 error
struct RawTrack: ParsableCommand {
@Option(help: "Location of dataset folder which should contain `frames` and `frames_txt`")
var datasetLocation: String = "./OIST_Data"
@Option(help: "Which bounding box to track")
var boxId: Int = 0
@Option(help: "Track for how many frames")
var trackFrames: Int = 10
@Flag(help: "Print progress information")
var verbose: Bool = false
/// Returns predictions for `videoName` using the raw pixel tracker.
func rawPixelTrack(dataset: OISTBeeVideo, length: Int) -> [OrientedBoundingBox] {
// Load the video and take a slice of it.
let videos = (0..<length).map { (i) -> Tensor<Float> in
if verbose {
print(".", terminator: "")
}
return withDevice(.cpu) { dataset.loadFrame(dataset.frameIds[i])! }
}
if verbose {
print("")
}
let startPatch = videos[0].patch(at: dataset.labels[0][boxId].location)
let startPose = dataset.labels[0][boxId].location.center
if verbose {
print("Creating tracker, startPose = \(startPose)")
}
var tracker = makeRawPixelTracker(frames: videos, target: startPatch)
// if verbose { tracker.optimizer.verbosity = .SUMMARY } For LM Optimizer
let prediction = tracker.infer(knownStart: Tuple1(startPose))
let boxes = tracker.frameVariableIDs.map { frameVariableIDs -> OrientedBoundingBox in
let poseID = frameVariableIDs.head
return OrientedBoundingBox(
center: prediction[poseID], rows: dataset.labels[0][boxId].location.rows, cols: dataset.labels[0][boxId].location.cols)
}
return boxes
}
func run() {
let dataURL = URL(fileURLWithPath: datasetLocation)
startTimer("DATASET_LOAD")
let dataset = OISTBeeVideo(directory: dataURL, deferLoadingFrames: true)!
stopTimer("DATASET_LOAD")
startTimer("RAW_TRACKING")
var bboxes: [OrientedBoundingBox]
bboxes = rawPixelTrack(dataset: dataset, length: trackFrames)
stopTimer("RAW_TRACKING")
let frameRawId = dataset.frameIds[trackFrames]
let image = dataset.loadFrame(frameRawId)!
if verbose {
print("Creating output plot")
}
startTimer("PLOTTING")
// plot(image, boxes: bboxes.indices.map {
// ("\($0)", bboxes[$0])
// }, margin: 10.0, scale: 0.5).show()
stopTimer("PLOTTING")
if verbose {
printTimers()
}
}
}
/// Tracking with a PPCA graph
struct PpcaTrack: ParsableCommand {
@Option(help: "Location of dataset folder which should contain `frames` and `frames_txt`")
var datasetLocation: String = "./OIST_Data"
@Option(help: "Which bounding box to track")
var boxId: Int = 0
@Option(help: "Track for how many frames")
var trackFrames: Int = 10
@Flag(help: "Print progress information")
var verbose: Bool = false
/// Returns predictions for `videoName` using the raw pixel tracker.
func ppcaTrack(dataset dataset_: OISTBeeVideo, length: Int, ppcaSize: Int = 10, ppcaSamples: Int = 100) -> [OrientedBoundingBox] {
var dataset = dataset_
dataset.labels = dataset.labels.map {
$0.filter({ $0.label == .Body })
}
// Make batch and do PPCA
let (batch, statistics) = makeOISTBatch(dataset: dataset, appearanceModelSize: (40, 70))
if verbose { print("Training PPCA model, \(batch.shape)...") }
var ppca = PPCA(latentSize: ppcaSize)
ppca.train(images: batch)
if verbose { print("Loading video frames...") }
startTimer("VIDEO_LOAD")
// Load the video and take a slice of it.
let videos = (0..<length).map { (i) -> Tensor<Float> in
return withDevice(.cpu) { dataset.loadFrame(dataset.frameIds[i])! }
}
stopTimer("VIDEO_LOAD")
let startPatch = statistics.normalized(videos[0].patch(at: dataset.labels[0][boxId].location))
let startPose = dataset.labels[0][boxId].location.center
let startLatent = ppca.encode(Tensor<Double>(startPatch))
if verbose {
print("Creating tracker, startPose = \(startPose)")
}
startTimer("MAKE_GRAPH")
var tracker = makePPCATracker(model: ppca, statistics: statistics, frames: videos, targetSize: (40, 70))
stopTimer("MAKE_GRAPH")
// For LM Optimizer
// if verbose { tracker.optimizer.verbosity = .SUMMARY }
// tracker.optimizer.cgls_precision = 1e-6
// tracker.optimizer.precision = 1e-2
startTimer("GRAPH_INFER")
let prediction = tracker.infer(knownStart: Tuple2(startPose, Vector10(flatTensor: startLatent)))
stopTimer("GRAPH_INFER")
let boxes = tracker.frameVariableIDs.map { frameVariableIDs -> OrientedBoundingBox in
let poseID = frameVariableIDs.head
return OrientedBoundingBox(
center: prediction[poseID], rows: dataset.labels[0][boxId].location.rows, cols: dataset.labels[0][boxId].location.cols)
}
return boxes
}
func run() {
let dataURL = URL(fileURLWithPath: datasetLocation)
if verbose {
print("Loading dataset...")
}
let dataset: OISTBeeVideo = { () -> OISTBeeVideo in
startTimer("DATASET_LOAD")
return OISTBeeVideo(directory: dataURL, deferLoadingFrames: true)!
}()
stopTimer("DATASET_LOAD")
if verbose {
print("Tracking...")
}
startTimer("PPCA_TRACKING")
var bboxes: [OrientedBoundingBox]
bboxes = ppcaTrack(dataset: dataset, length: trackFrames)
stopTimer("PPCA_TRACKING")
let frameRawId = dataset.frameIds[trackFrames]
let image = dataset.loadFrame(frameRawId)!
if verbose {
print("Creating output plot")
}
startTimer("PLOTTING")
// plot(image, boxes: bboxes.indices.map {
// ("\($0)", bboxes[$0])
// }, margin: 10.0, scale: 0.5).show()
stopTimer("PLOTTING")
if verbose {
printTimers()
}
}
}
/// The dimension of the hidden layer in the RAE appearance model.
let kHiddenDimension = 100
/// Tracking with a Naive Bayes with RAE
struct NaiveRae: ParsableCommand {
@Option(help: "Where to load the RAE weights")
var loadWeights: String = "./oist_rae_weight.npy"
@Option(help: "Which bounding box to track")
var boxId: Int = 0
@Option(help: "Track for how many frames")
var trackFrames: Int = 10
@Option(help: "Track the target from frame x")
var trackStartFrame: Int = 250
@Option(help: "The dimension of the latent code in the RAE appearance model")
var kLatentDimension = 10
@Flag(help: "Print progress information")
var verbose: Bool = false
/// Returns predictions for `videoName` using the raw pixel tracker.
func naiveRaeTrack(dataset dataset_: OISTBeeVideo, length: Int, startFrom: Int) -> [OrientedBoundingBox] {
var dataset = dataset_
dataset.labels = dataset.labels.map {
$0.filter({ $0.label == .Body })
}
// Make batch and do RAE
let (batch, _) = dataset.makeBatch(appearanceModelSize: (40, 70), batchSize: 200)
var statistics = FrameStatistics(batch)
statistics.mean = Tensor(62.26806976644069)
statistics.standardDeviation = Tensor(37.44683834503672)
let backgroundBatch = dataset.makeBackgroundBatch(
patchSize: (40, 70), appearanceModelSize: (40, 70),
statistics: statistics,
batchSize: 300
)
let (imageHeight, imageWidth, imageChannels) =
(batch.shape[1], batch.shape[2], batch.shape[3])
if verbose { print("Loading RAE model, \(batch.shape)...") }
let np = Python.import("numpy")
var rae = DenseRAE(
imageHeight: imageHeight, imageWidth: imageWidth, imageChannels: imageChannels,
hiddenDimension: kHiddenDimension, latentDimension: kLatentDimension
)
rae.load(weights: np.load(loadWeights, allow_pickle: true))
if verbose { print("Fitting Naive Bayes model") }
let batchPositive = rae.encode(batch)
let foregroundModel = MultivariateGaussian(from:batchPositive, regularizer: 1e-3)
let batchNegative = rae.encode(backgroundBatch)
let backgroundModel = GaussianNB(from: batchNegative, regularizer: 1e-3)
if verbose {
print("Foreground: \(foregroundModel)")
print("Background: \(backgroundModel)")
}
if verbose { print("Loading video frames...") }
startTimer("VIDEO_LOAD")
// Load the video and take a slice of it.
let videos = (0..<length).map { (i) -> Tensor<Float> in
return withDevice(.cpu) { dataset.loadFrame(dataset.frameIds[startFrom + i])! }
}
stopTimer("VIDEO_LOAD")
let startPose = dataset.labels[startFrom][boxId].location.center
if verbose {
print("Creating tracker, startPose = \(startPose)")
}
startTimer("MAKE_GRAPH")
var tracker = makeNaiveBayesAETracker(
model: rae,
statistics: statistics,
frames: videos,
targetSize: (dataset.labels[startFrom][boxId].location.rows, dataset.labels[startFrom][boxId].location.cols),
foregroundModel: foregroundModel, backgroundModel: backgroundModel
)
stopTimer("MAKE_GRAPH")
if verbose { print("Starting Optimization...") }
// For LM Optimizer
// if verbose { tracker.optimizer.verbosity = .SUMMARY }
// tracker.optimizer.cgls_precision = 1e-7
// tracker.optimizer.precision = 1e-4
// tracker.optimizer.max_iteration = 200
startTimer("GRAPH_INFER")
let prediction = tracker.infer(knownStart: Tuple1(startPose))
stopTimer("GRAPH_INFER")
let boxes = tracker.frameVariableIDs.map { frameVariableIDs -> OrientedBoundingBox in
let poseID = frameVariableIDs.head
return OrientedBoundingBox(
center: prediction[poseID], rows: dataset.labels[startFrom][boxId].location.rows, cols: dataset.labels[startFrom][boxId].location.cols)
}
return boxes
}
func run() {
if verbose {
print("Loading dataset...")
}
startTimer("DATASET_LOAD")
let dataset: OISTBeeVideo = OISTBeeVideo(deferLoadingFrames: true)!
stopTimer("DATASET_LOAD")
if verbose {
print("Tracking...")
}
startTimer("RAE_TRACKING")
var bboxes: [OrientedBoundingBox]
bboxes = naiveRaeTrack(dataset: dataset, length: trackFrames, startFrom: trackStartFrame)
stopTimer("RAE_TRACKING")
let frameRawId = dataset.frameIds[trackStartFrame + trackFrames]
let image = dataset.loadFrame(frameRawId)!
if verbose {
print("Creating output plot")
}
startTimer("PLOTTING")
// plot(image, boxes: bboxes.indices.map {
// ("\($0)", bboxes[$0])
// }, margin: 10.0, scale: 0.5).show()
stopTimer("PLOTTING")
if verbose {
printTimers()
}
}
}
/// Trains a RAE on the VOT dataset.
struct TrainRAE: ParsableCommand {
@Option(help: "Load weights from this file before training")
var loadWeights: String?
@Option(help: "Save weights to this file after training")
var saveWeights: String = "./oist_rae_weight"
@Option(help: "Number of iterations for each epoch")
var iterationCount: Int = 300
@Option(help: "Number of epochs")
var epochCount: Int = 200
@Option(help: "Number of rows in the appearance model output")
var appearanceModelRows: Int = 40
@Option(help: "Number of columns in the appearance model output")
var appearanceModelCols: Int = 70
@Option(help: "The dimension of the latent code in the RAE appearance model")
var kLatentDimension = 10
func run() {
let np = Python.import("numpy")
let dataset: OISTBeeVideo = { () -> OISTBeeVideo in
startTimer("DATASET_LOAD")
return OISTBeeVideo(directory: URL(fileURLWithPath: "./OIST_Data"), deferLoadingFrames: true)!
}()
stopTimer("DATASET_LOAD")
let (bundle, statistics) = makeOISTTrainingBatch(dataset: dataset, appearanceModelSize: (40, 70), batchSize: 20000, seed: Int.random(in: 0..<9999999))
print("Dataset size: \(bundle.count)")
print("Statistics: \(statistics)")
let (imageHeight, imageWidth, imageChannels) =
(bundle[0].shape[0], bundle[0].shape[1], bundle[0].shape[2])
var model = DenseRAE(
imageHeight: imageHeight, imageWidth: imageWidth, imageChannels: imageChannels,
hiddenDimension: kHiddenDimension, latentDimension: kLatentDimension)
if let loadWeights = loadWeights {
let weights = np.load(loadWeights, allow_pickle: true)
model.load(weights: weights)
}
let loss = DenseRAELoss()
// _ = loss(model, batch, printLoss: true)
// Use ADAM as optimizer
let optimizer = Adam(for: model)
optimizer.learningRate = 1e-3
// Thread-local variable that model layers read to know their mode
Context.local.learningPhase = .training
let epochs = TrainingEpochs(samples: bundle, batchSize: 200)
var trainLossResults: [Double] = []
for (epochIndex, epoch) in epochs.prefix(epochCount).enumerated() {
var epochLoss: Double = 0
var batchCount: Int = 0
// epoch is a Slices object, see below
for batchSamples in epoch {
let batch = batchSamples.collated
let (loss, grad) = valueWithGradient(at: model) { loss($0, batch) }
optimizer.update(&model, along: grad)
epochLoss += loss.scalarized()
batchCount += 1
}
epochLoss /= Double(batchCount)
trainLossResults.append(epochLoss)
if epochIndex % 50 == 0 {
print("Epoch \(epochIndex): Loss: \(epochLoss)")
}
}
_ = loss(model, Tensor<Double>(stacking: bundle), printLoss: true)
np.save(saveWeights, np.array(model.numpyWeights, dtype: Python.object))
}
}
/// PPCA with probabilistic model
///
/// Tracking with a Naive Bayes with RAE
struct NaivePca: ParsableCommand {
@Option(help: "Where to load the RAE weights")
var loadWeights: String = "./oist_rae_weight.npy"
@Option(help: "Which bounding box to track")
var boxId: Int = 0
@Option(help: "Track for how many frames")
var trackFrames: Int = 10
@Option(help: "Track the target from frame x")
var trackStartFrame: Int = 250
@Option(help: "The dimension of the latent code in the RAE appearance model")
var kLatentDimension = 10
@Flag(help: "Print progress information")
var verbose: Bool = false
/// Returns predictions for `videoName` using the raw pixel tracker.
func naivePpcaTrack(dataset dataset_: OISTBeeVideo, length: Int, startFrom: Int) -> [OrientedBoundingBox] {
var dataset = dataset_
dataset.labels = dataset.labels.map {
$0.filter({ $0.label == .Body })
}
// Make batch and do RAE
let (batch, _) = dataset.makeBatch(appearanceModelSize: (40, 70), batchSize: 300)
var statistics = FrameStatistics(batch)
statistics.mean = Tensor(62.26806976644069)
statistics.standardDeviation = Tensor(37.44683834503672)
let backgroundBatch = dataset.makeBackgroundBatch(
patchSize: (40, 70), appearanceModelSize: (40, 70),
statistics: statistics,
batchSize: 300
)
var ppca = PPCA(latentSize: kLatentDimension)
ppca.train(images: batch)
if verbose { print("Fitting Naive Bayes model") }
let batchPositive = ppca.encode(batch)
let foregroundModel = MultivariateGaussian(from:batchPositive, regularizer: 1e-3)
let batchNegative = ppca.encode(backgroundBatch)
let backgroundModel = GaussianNB(from: batchNegative, regularizer: 1e-3)
if verbose {
print("Foreground: \(foregroundModel)")
print("Background: \(backgroundModel)")
}
if verbose { print("Loading video frames...") }
startTimer("VIDEO_LOAD")
// Load the video and take a slice of it.
let videos = (0..<length).map { (i) -> Tensor<Float> in
return withDevice(.cpu) { dataset.loadFrame(dataset.frameIds[startFrom + i])! }
}
stopTimer("VIDEO_LOAD")
let startPose = dataset.labels[startFrom][boxId].location.center
if verbose {
print("Creating tracker, startPose = \(startPose)")
}
startTimer("MAKE_GRAPH")
var tracker = makeNaiveBayesPCATracker(
model: ppca,
statistics: statistics,
frames: videos,
targetSize: (dataset.labels[startFrom][boxId].location.rows, dataset.labels[startFrom][boxId].location.cols),
foregroundModel: foregroundModel, backgroundModel: backgroundModel
)
stopTimer("MAKE_GRAPH")
if verbose { print("Starting Optimization...") }
// For LM Optimizer
// if verbose { tracker.optimizer.verbosity = .SUMMARY }
// tracker.optimizer.cgls_precision = 1e-7
// tracker.optimizer.precision = 1e-4
// tracker.optimizer.max_iteration = 200
startTimer("GRAPH_INFER")
let prediction = tracker.infer(knownStart: Tuple1(startPose))
stopTimer("GRAPH_INFER")
let boxes = tracker.frameVariableIDs.map { frameVariableIDs -> OrientedBoundingBox in
let poseID = frameVariableIDs.head
return OrientedBoundingBox(
center: prediction[poseID], rows: dataset.labels[startFrom][boxId].location.rows, cols: dataset.labels[startFrom][boxId].location.cols)
}
return boxes
}
func run() {
if verbose {
print("Loading dataset...")
}
startTimer("DATASET_LOAD")
let dataset: OISTBeeVideo = OISTBeeVideo(deferLoadingFrames: true)!
stopTimer("DATASET_LOAD")
if verbose {
print("Tracking...")
}
startTimer("PPCA_TRACKING")
var bboxes: [OrientedBoundingBox]
bboxes = naivePpcaTrack(dataset: dataset, length: trackFrames, startFrom: trackStartFrame)
stopTimer("PPCA_TRACKING")
let frameRawId = dataset.frameIds[trackStartFrame + trackFrames]
let image = dataset.loadFrame(frameRawId)!
if verbose {
print("Creating output plot")
}
startTimer("PLOTTING")
// plot(image, boxes: bboxes.indices.map {
// ("\($0)", bboxes[$0])
// }, margin: 10.0, scale: 0.5).show()
stopTimer("PLOTTING")
if verbose {
printTimers()
}
}
}
struct VisualizeTrack: ParsableCommand {
@Option(help: "Index of the track to visualize")
var trackIndex: Int
@Option(help: "Directory for the output frames")
var output: String
func run() {
let dataset = OISTBeeVideo(deferLoadingFrames: true)!
dataset.tracks[trackIndex].render(to: output, video: dataset)
}
}
// It is important to set the global threadpool before doing anything else, so that nothing
// accidentally uses the default threadpool.
ComputeThreadPools.global =
NonBlockingThreadPool<PosixConcurrencyPlatform>(name: "mypool", threadCount: 12)
OISTVisualizationTool.main()