I’m having hard time reading cifar-10 dataset in swift, this is what I’m doing
public extension String {
/**
* Download a URL string
*/
func download() -> String
{
let fname = Path(self).name
request.urlretrieve(self, fname)
return String(fname)!
}
/**
* Pickle a filename
*/
func load(_ encoding: String = "utf-8") -> PythonObject
{
return pickle.load(gzip.open(self), encoding: encoding)
}
/**
* Untar filename
*/
func untar()
{
let tar = tarfile.open(self, mode: "r:gz")
tar.extractall()
tar.close()
}
}
let cifar10 = "https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz"
cifar10.download().untar()
let data_batch_1 = pickle.load(Python.open("cifar-10-batches-py/data_batch_1", mode: "rb"), encoding:"bytes")
Now this data_batch_1
looks like this
{b'batch_label': b'training batch 1 of 5', b'labels': [6, ...., dtype=uint8), b'filenames':...}
How I could read this data_batch_1
dic?
data_batch_1.data
Fatal error: Could not access PythonObject member 'data': file /swift-base/swift/stdlib/public/Python/Python.swift, line 537
Current stack trace:
frame #4: 0x00007f033275f287 $__lldb_expr505`main at <Cell 33>:1:1