Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVPR 2021 Changes #273

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2fb049e
updated tracker to have 1.0 robustness
acoadmarmon Feb 10, 2021
d624ebb
fixed merge conflicts
acoadmarmon Feb 10, 2021
483bfa2
removed unecessary comments
acoadmarmon Feb 10, 2021
1d65667
removed call to Python.list and validated functionality.
acoadmarmon Feb 10, 2021
e2a5a36
Merge pull request #264 from acoadmarmon/main
ProfFan Feb 10, 2021
65da84d
updating all the Source files
Aug 27, 2021
d375360
committing the script files
Aug 27, 2021
a83c45c
more changes
Sep 27, 2021
aac1a00
mode code
Sep 27, 2021
a68512f
adding tests
Sep 27, 2021
114771f
commented out tests
Sep 27, 2021
50f1bdc
removed GD test
Sep 27, 2021
9034540
Merge pull request #270 from brandoDecu/main
brandoDecu Sep 30, 2021
d28ebee
Scripts and supporting code Big Transfer tracking
acoadmarmon Dec 9, 2021
e3af5ca
cleaned up the code
Dec 9, 2021
f7ed2d0
removed BrandoTests
Dec 9, 2021
fcaa808
Merge pull request #271 from brandoDecu/cleanedNNClassifier
brandoDecu Dec 9, 2021
31e7939
Merge branch 'NNClassifier' into NNClassifier
acoadmarmon Dec 9, 2021
b123bcf
Merge pull request #272 from acoadmarmon/NNClassifier
brandoDecu Dec 9, 2021
778f89b
Update Andrew01.swift
brandoDecu Dec 9, 2021
909a094
Update Andrew01.swift
brandoDecu Dec 9, 2021
2a145c2
Delete Brando09.swift
brandoDecu Dec 9, 2021
46513be
Delete Brando04d1.swift
brandoDecu Dec 9, 2021
d1dcc67
Update main.swift
brandoDecu Dec 9, 2021
af643ad
Update Brando05.swift
brandoDecu Dec 9, 2021
d30edbb
Update Brando06.swift
brandoDecu Dec 9, 2021
d196b13
Update Fan05.swift
acoadmarmon Dec 9, 2021
b76fd19
Update main.swift
acoadmarmon Dec 9, 2021
4ff8195
Update Brando07.swift
brandoDecu Dec 9, 2021
9edb36b
Update Brando08.swift
brandoDecu Dec 9, 2021
218a0ef
Update FactorBoilerplate.swift
acoadmarmon Dec 9, 2021
06f530b
Update MultivariateGaussian.swift
acoadmarmon Dec 9, 2021
469e6d1
Update GradientDescentTests.swift
acoadmarmon Dec 9, 2021
715854c
Update ProbablisticTrackingFactor.swift
acoadmarmon Dec 9, 2021
9001b2c
Update Brando12.swift
brandoDecu Dec 9, 2021
584f186
Update TrackingMetrics.swift
acoadmarmon Dec 9, 2021
0db61ed
Update TrackingFactorGraph.swift
acoadmarmon Dec 9, 2021
54d589f
Update ProbabilisticTracker.swift
acoadmarmon Dec 9, 2021
d44eb44
Update OISTBeeVideo+Batches.swift
acoadmarmon Dec 9, 2021
eedd730
Update FactorGraphTests.swift
acoadmarmon Dec 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions Examples/OISTVisualizationTool/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ struct ViewFrame: ParsableCommand {

let image = dataset.loadFrame(frameRawId)!

plot(image, boxes: dataset.labels[frameId].enumerated().map {
(String($0), $1.location)
}, margin: 10.0, scale: 0.5).show()
// plot(image, boxes: dataset.labels[frameId].enumerated().map {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed because issue with plotly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should maybe just remove these?

// (String($0), $1.location)
// }, margin: 10.0, scale: 0.5).show()
}
}

Expand Down Expand Up @@ -118,7 +118,7 @@ struct RawTrack: ParsableCommand {

var tracker = makeRawPixelTracker(frames: videos, target: startPatch)

if verbose { tracker.optimizer.verbosity = .SUMMARY }
// if verbose { tracker.optimizer.verbosity = .SUMMARY } For LM Optimizer

let prediction = tracker.infer(knownStart: Tuple1(startPose))

Expand Down Expand Up @@ -150,9 +150,9 @@ struct RawTrack: ParsableCommand {
print("Creating output plot")
}
startTimer("PLOTTING")
plot(image, boxes: bboxes.indices.map {
("\($0)", bboxes[$0])
}, margin: 10.0, scale: 0.5).show()
// plot(image, boxes: bboxes.indices.map {
// ("\($0)", bboxes[$0])
// }, margin: 10.0, scale: 0.5).show()
stopTimer("PLOTTING")

if verbose {
Expand Down Expand Up @@ -207,11 +207,11 @@ struct PpcaTrack: ParsableCommand {
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 }

if verbose { tracker.optimizer.verbosity = .SUMMARY }

tracker.optimizer.cgls_precision = 1e-6
tracker.optimizer.precision = 1e-2
// tracker.optimizer.cgls_precision = 1e-6
// tracker.optimizer.precision = 1e-2

startTimer("GRAPH_INFER")
let prediction = tracker.infer(knownStart: Tuple2(startPose, Vector10(flatTensor: startLatent)))
Expand Down Expand Up @@ -255,9 +255,9 @@ struct PpcaTrack: ParsableCommand {
print("Creating output plot")
}
startTimer("PLOTTING")
plot(image, boxes: bboxes.indices.map {
("\($0)", bboxes[$0])
}, margin: 10.0, scale: 0.5).show()
// plot(image, boxes: bboxes.indices.map {
// ("\($0)", bboxes[$0])
// }, margin: 10.0, scale: 0.5).show()
stopTimer("PLOTTING")

if verbose {
Expand Down Expand Up @@ -358,11 +358,12 @@ struct NaiveRae: ParsableCommand {
stopTimer("MAKE_GRAPH")

if verbose { print("Starting Optimization...") }
if verbose { tracker.optimizer.verbosity = .SUMMARY }
// 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
// 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))
Expand Down Expand Up @@ -402,9 +403,9 @@ struct NaiveRae: ParsableCommand {
print("Creating output plot")
}
startTimer("PLOTTING")
plot(image, boxes: bboxes.indices.map {
("\($0)", bboxes[$0])
}, margin: 10.0, scale: 0.5).show()
// plot(image, boxes: bboxes.indices.map {
// ("\($0)", bboxes[$0])
// }, margin: 10.0, scale: 0.5).show()
stopTimer("PLOTTING")

if verbose {
Expand Down Expand Up @@ -578,11 +579,12 @@ struct NaivePca: ParsableCommand {
stopTimer("MAKE_GRAPH")

if verbose { print("Starting Optimization...") }
if verbose { tracker.optimizer.verbosity = .SUMMARY }
// 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
// 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))
Expand Down Expand Up @@ -622,9 +624,9 @@ struct NaivePca: ParsableCommand {
print("Creating output plot")
}
startTimer("PLOTTING")
plot(image, boxes: bboxes.indices.map {
("\($0)", bboxes[$0])
}, margin: 10.0, scale: 0.5).show()
// plot(image, boxes: bboxes.indices.map {
// ("\($0)", bboxes[$0])
// }, margin: 10.0, scale: 0.5).show()
stopTimer("PLOTTING")

if verbose {
Expand Down
36 changes: 0 additions & 36 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
{
"object": {
"pins": [
{
"package": "CSV.swift",
"repositoryURL": "https://github.com/yaslab/CSV.swift.git",
"state": {
"branch": null,
"revision": "81d2874c51db364d7e1d71b0d99018a294c87ac1",
"version": "2.4.3"
}
},
{
"package": "Penguin",
"repositoryURL": "https://github.com/saeta/penguin.git",
Expand All @@ -19,15 +10,6 @@
"version": null
}
},
{
"package": "Plotly",
"repositoryURL": "https://github.com/vojtamolda/Plotly.swift",
"state": {
"branch": null,
"revision": "6e80119ba37b913e5460459556e2bf58f02eba67",
"version": "0.4.0"
}
},
{
"package": "swift-argument-parser",
"repositoryURL": "https://github.com/apple/swift-argument-parser.git",
Expand All @@ -46,24 +28,6 @@
"version": "0.1.0"
}
},
{
"package": "swift-models",
"repositoryURL": "https://github.com/tensorflow/swift-models.git",
"state": {
"branch": null,
"revision": "b2fc0325bf9d476bf2d7a4cd0a09d36486c506e4",
"version": null
}
},
{
"package": "SwiftProtobuf",
"repositoryURL": "https://github.com/apple/swift-protobuf.git",
"state": {
"branch": null,
"revision": "da9a52be9cd36c63993291ce3f1b65dafcd1e826",
"version": "1.14.0"
}
},
{
"package": "swift-tools-support-core",
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
Expand Down
4 changes: 0 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ let package = Package(
.package(name: "TensorBoardX", url: "https://github.com/ProfFan/tensorboardx-s4tf.git", from: "0.1.3"),
.package(url: "https://github.com/apple/swift-tools-support-core.git", .branch("swift-5.2-branch")),
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "0.3.0"),
.package(name: "Plotly", url: "https://github.com/vojtamolda/Plotly.swift", from: "0.4.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand All @@ -57,7 +56,6 @@ let package = Package(
name: "BeeDataset",
dependencies: [
"SwiftFusion",
"Plotly",
"ModelSupport",
]),
.target(
Expand Down Expand Up @@ -86,7 +84,6 @@ let package = Package(
"BeeTracking",
.product(name: "PenguinParallelWithFoundation", package: "Penguin"),
"SwiftFusion",
"Plotly",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Examples/OISTVisualizationTool"),
Expand All @@ -97,7 +94,6 @@ let package = Package(
"BeeTracking",
.product(name: "PenguinParallelWithFoundation", package: "Penguin"),
"SwiftFusion",
"Plotly",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
],
path: "Scripts",
Expand Down
50 changes: 29 additions & 21 deletions Scripts/Andrew01.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ import PenguinStructures

/// Andrew01: RAE Tracker
struct Andrew01: ParsableCommand {
@Option(help: "Run on track number x")
var trackId: Int = 0

@Option(help: "Run for number of frames")
var trackLength: Int = 80

@Option(help: "Size of feature space")
var featureSize: Int = 5
var featureSize: Int = 256

@Option(help: "Pretrained weights")
var weightsFile: String?
Expand All @@ -27,10 +24,12 @@ struct Andrew01: ParsableCommand {
// Make sure you have a folder `Results/andrew01` before running
func run() {
let np = Python.import("numpy")
let kHiddenDimension = 100
let kHiddenDimension = 512

let (imageHeight, imageWidth, imageChannels) =
(40, 70, 1)


var rae = DenseRAE(
imageHeight: imageHeight, imageWidth: imageWidth, imageChannels: imageChannels,
hiddenDimension: kHiddenDimension, latentDimension: featureSize
Expand All @@ -42,20 +41,25 @@ struct Andrew01: ParsableCommand {
rae.load(weights: np.load("./oist_rae_weight_\(featureSize).npy", allow_pickle: true))
}

// let (imageHeight, imageWidth, imageChannels) =
// (40, 70, 1)

// let rp = RandomProjection(fromShape: TensorShape([imageHeight, imageWidth, imageChannels]), toFeatureSize: featureSize)

let trainingDatasetSize = 100

let dataDir = URL(fileURLWithPath: "./OIST_Data")
let data = OISTBeeVideo(directory: dataDir, length: 100)!
let testData = OISTBeeVideo(directory: dataDir, afterIndex: 100, length: 80)!
let data = OISTBeeVideo(directory: dataDir, length: trainingDatasetSize)!
let testData = OISTBeeVideo(directory: dataDir, afterIndex: trainingDatasetSize, length: trackLength)!

let trackerEvaluation = TrackerEvaluationDataset(testData)

let evalTracker: Tracker = {frames, start in
let trainingDatasetSize = 100
var tracker = trainProbabilisticTracker(
trainingData: data,
encoder: rae,
frames: frames,
boundingBoxSize: (40, 70),
withFeatureSize: 5,
withFeatureSize: featureSize,
fgRandomFrameCount: trainingDatasetSize,
bgRandomFrameCount: trainingDatasetSize
)
Expand All @@ -64,32 +68,36 @@ struct Andrew01: ParsableCommand {

return track
}
let plt = Python.import("matplotlib.pyplot")
let sequenceCount = 1
var results = trackerEvaluation.evaluate(evalTracker, sequenceCount: sequenceCount, deltaAnchor: 175, outputFile: "andrew01")

var results = trackerEvaluation.evaluate(evalTracker, sequenceCount: 5, deltaAnchor: 175, outputFile: "andrew01")


for (index, value) in results.sequences.prefix(5).enumerated() {
for (index, value) in results.sequences.prefix(sequenceCount).enumerated() {
var i: Int = 0
zip(value.subsequences.first!.frames, zip(value.subsequences.first!.prediction, value.subsequences.first!.groundTruth)).map {
let (fig, axes) = plotPatchWithGT(frame: $0.0, actual: $0.1.0.center, expected: $0.1.1.center)
let (fig, axes) = plotFrameWithPatches(frame: $0.0, actual: $0.1.0.center, expected: $0.1.1.center, firstGroundTruth: value.subsequences.first!.groundTruth.first!.center)
fig.savefig("Results/andrew01/sequence\(index)/andrew01_\(i).png", bbox_inches: "tight")
plt.close("all")
i = i + 1
}
let plt = Python.import("matplotlib.pyplot")


let (fig, axes) = plt.subplots(1, 2, figsize: Python.tuple([20, 20])).tuple2
fig.suptitle("Tracking positions and Subsequence Average Overlap with Accuracy \(String(format: "%.2f", value.subsequences.first!.metrics.accuracy)) and Robustness \(value.subsequences.first!.metrics.robustness).")

value.subsequences.map {
plotTrajectory(
track: $0.prediction.map{$0.center}, withGroundTruth: $0.groundTruth.map{$0.center}, on: axes[0],
withTrackColors: plt.cm.jet, withGtColors: plt.cm.gray
plotPoseDifference(
track: $0.prediction.map{$0.center}, withGroundTruth: $0.groundTruth.map{$0.center}, on: axes[0]
)
}
plotOverlap(
metrics: value.subsequences.first!.metrics, on: axes[1]
)
fig.savefig("Results/andrew01/andrew01_subsequence\(index).pdf", bbox_inches: "tight")
fig.savefig("Results/andrew01/andrew01_subsequence\(index).png", bbox_inches: "tight")
print("Accuracy for sequence is \(value.sequenceMetrics.accuracy) with Robustness of \(value.sequenceMetrics.robustness)")
}

print("Accuracy for all sequences is \(results.trackerMetrics.accuracy) with Robustness of \(results.trackerMetrics.robustness)")



Expand All @@ -103,4 +111,4 @@ fileprivate func unpack<A, B>(_ t: Tuple2<A, B>) -> (A, B) {
/// Returns `t` as a Swift tuple.
fileprivate func unpack<A>(_ t: Tuple1<A>) -> (A) {
return (t.head)
}
}
Loading