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

[SR-9612] swift crashes with simple MNIST images reader #52058

Closed
swift-ci opened this issue Jan 7, 2019 · 1 comment
Closed

[SR-9612] swift crashes with simple MNIST images reader #52058

swift-ci opened this issue Jan 7, 2019 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 7, 2019

Previous ID SR-9612
Radar None
Original Reporter xiejw (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Linux, swift built recently

Additional Detail from JIRA
Votes 0
Component/s Swift for TensorFlow
Labels Bug
Assignee pschuh (JIRA)
Priority Medium

md5: c4b9aefb499c27fd6a307c338f91f51f

Issue Description:

The following code can run with swiftc -ltensorflow, but not swift only.

import TensorFlow
import Python

let np = Python.import("numpy")

func readFile(_ filename: String) -> [UInt8] {
let d = Python.open(filename, "rb").read()
return Array(numpyArray: np.frombuffer(d, dtype: np.uint8))!
}

func readMNIST(imagesFile: String, labelsFile: String) ->
(images: Tensor<Float>, labels: Tensor<Int32>) {
// print("Reading data.")

let images = readFile(imagesFile).dropFirst(16).map { Float($0) }
let labels = readFile(labelsFile).dropFirst(8).map { Int32($0) }
let rowCount = Int32(labels.count)
let columnCount = Int32(images.count) / rowCount

// // print("Constructing data tensors.")
let imagesTensor = Tensor(shape: [rowCount, columnCount], scalars: images) / 255
let labelsTensor = Tensor(labels)
return (imagesTensor, labelsTensor)
}

func train() {
// Get training data.
let (images, numericLabels) = readMNIST(imagesFile: "train-images-idx3-ubyte",
labelsFile: "train-labels-idx1-ubyte")
print(images.shape)
print(numericLabels.shape)
}

train()

@dan-zheng
Copy link
Collaborator

Fixed in #21784

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift for tensorflow
Projects
None yet
Development

No branches or pull requests

2 participants