Skip to content

Commit

Permalink
Added comments and removed thread debugging statements
Browse files Browse the repository at this point in the history
  • Loading branch information
acoadmarmon committed Jan 22, 2021
1 parent c937270 commit 54a8bf6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Scripts/Andrew01.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

import PenguinStructures

/// Fan03: RP Tracker, with sampling-based initialization
/// Andrew01: RAE Tracker
struct Andrew01: ParsableCommand {
@Option(help: "Run on track number x")
var trackId: Int = 0
Expand All @@ -23,8 +23,8 @@ struct Andrew01: ParsableCommand {
@Option(help: "Pretrained weights")
var weightsFile: String?

// Just runs an RP tracker and saves image to file
// Make sure you have a folder `Results/frank02` before running
// Runs RAE tracker on n number of sequences and outputs relevant images and statistics
// Make sure you have a folder `Results/andrew01` before running
func run() {
let np = Python.import("numpy")
let kHiddenDimension = 100
Expand Down
2 changes: 1 addition & 1 deletion Sources/BeeTracking/OISTBeeVideo+Batches.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ extension OISTBeeVideo {
rows: patchSize.0, cols: patchSize.1))
}
}

return obbs
}

Expand Down
26 changes: 12 additions & 14 deletions Sources/BeeTracking/TrackingFactorGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,31 +272,29 @@ public func getTrainingBatches(
) -> (fg: Tensor<Double>, bg: Tensor<Double>, statistics: FrameStatistics) {
precondition(dataset.frames.count >= bgRandomFrameCount)
let np = Python.import("numpy")

var statistics = FrameStatistics(Tensor<Double>(0.0))
statistics.mean = Tensor(62.26806976644069)
statistics.standardDeviation = Tensor(37.44683834503672)

print("entering")
/// Caching
let cachePath = "./training_batch_cache"
let cacheURL = URL(fileURLWithPath: "\(cachePath)_fg.npy")
print("entering2")
if useCache && FileManager.default.fileExists(atPath: cacheURL.path) {
let foregroundBatch = Tensor<Double>(numpy: np.load("\(cachePath)_fg.npy"))!
let backgroundBatch = Tensor<Double>(numpy: np.load("\(cachePath)_bg.npy"))!
print("hi")

precondition(foregroundBatch.shape[0] == fgBatchSize, "Wrong foreground dataset cache, please delete and regenerate!")
precondition(backgroundBatch.shape[0] == bgBatchSize, "Wrong background dataset cache, please delete and regenerate!")
print("bye")

return (fg: foregroundBatch, bg: backgroundBatch, statistics: statistics)
}
print("entering3")

let foregroundBatch = dataset.makeBatch(
statistics: statistics, appearanceModelSize: boundingBoxSize,
randomFrameCount: fgRandomFrameCount, batchSize: fgBatchSize
)
print("entering4")

let backgroundBatch = dataset.makeBackgroundBatch(
patchSize: boundingBoxSize, appearanceModelSize: boundingBoxSize,
statistics: statistics,
Expand All @@ -308,7 +306,7 @@ public func getTrainingBatches(
np.save("\(cachePath)_fg", foregroundBatch.makeNumpyArray())
np.save("\(cachePath)_bg", backgroundBatch.makeNumpyArray())
}
print("leaving function")

return (fg: foregroundBatch, bg: backgroundBatch, statistics: statistics)
}

Expand All @@ -328,10 +326,11 @@ public func trainRPTracker(trainingData: OISTBeeVideo,
fgRandomFrameCount: fgRandomFrameCount,
bgRandomFrameCount: bgRandomFrameCount
)
print(statistics)

let randomProjector = RandomProjection(
fromShape: [boundingBoxSize.0, boundingBoxSize.1, 1], toFeatureSize: d
)

let batchPositive = randomProjector.encode(fg)
let foregroundModel = MultivariateGaussian(from: batchPositive, given: 1e-3)

Expand All @@ -343,6 +342,7 @@ public func trainRPTracker(trainingData: OISTBeeVideo,
frames: frames, targetSize: boundingBoxSize,
foregroundModel: foregroundModel, backgroundModel: backgroundModel
)

return tracker
}

Expand All @@ -362,7 +362,6 @@ public func createSingleTrack(
return (track, groundTruth)
}


/// Runs the random projections tracker
/// Given a training set, it will train an RP tracker
/// and run it on one track in the test set:
Expand All @@ -375,7 +374,7 @@ public func runRPTracker(
savePatchesIn resultDirectory: String? = nil
) -> (fig: PythonObject, track: [Pose2], groundTruth: [Pose2]) {
// train foreground and background model and create tracker
var trainingData = OISTBeeVideo(directory: directory, length: 100)!
let trainingData = OISTBeeVideo(directory: directory, length: 100)!
let testData = OISTBeeVideo(directory: directory, afterIndex: 100, length: forFrames)!

precondition(testData.tracks[trackIndex].boxes.count == forFrames, "track length and required does not match")
Expand All @@ -384,14 +383,13 @@ public func runRPTracker(
trainingData: trainingData,
frames: testData.frames, boundingBoxSize: (40, 70), withFeatureSize: d, usingEM :EMflag
)


// Run the tracker and return track with ground truth

// Run the tracker and return track with ground truth
let (track, groundTruth) = createSingleTrack(
onTrack: trackIndex, withTracker: &tracker,
andTestData: testData, withSampling: samplingFlag
)
// let _ = trackerEvaluation.evaluate(makeProbabilisticTracker())

// Now create trajectory and metrics plot
let plt = Python.import("matplotlib.pyplot")
let (fig, axes) = plt.subplots(2, 1, figsize: Python.tuple([6, 12])).tuple2
Expand Down

0 comments on commit 54a8bf6

Please sign in to comment.