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

Apply some optimisations in PoseNet #289

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ extension Data {

/// Convert a Data instance to Array representation.
func toArray<T>(type: T.Type) -> [T] where T: AdditiveArithmetic {
var array = [T](repeating: T.zero, count: self.count / MemoryLayout<T>.stride)
_ = array.withUnsafeMutableBytes { self.copyBytes(to: $0) }
return array
[T].init(unsafeUninitializedCapacity: self.count / MemoryLayout<T>.stride) {
bufPtr, initializedCount in
bufPtr.withMemoryRebound(to: UInt8.self) { reboundBufPtr in
self.withUnsafeBytes { _ = reboundBufPtr.initialize(from: $0) }
}
initializedCount = bufPtr.count
}
}
}

Expand All @@ -55,7 +59,7 @@ struct FlatArray<Element: AdditiveArithmetic> {
}

var result = 0
for i in 0..<dimensions.count {
for i in dimensions.indices {
guard dimensions[i] > index[i] else {
fatalError("Invalid index: \(index[i]) is bigger than \(dimensions[i])")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ class ModelDataHandler {
var maxCol = 0
for row in 0..<Model.output.height {
for col in 0..<Model.output.width {
if heats[0, row, col, keypoint] > maxValue {
maxValue = heats[0, row, col, keypoint]
let value = heats[0, row, col, keypoint]
if value > maxValue {
maxValue = value
maxRow = row
maxCol = col
}
Expand Down