3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
7 from caffe2.python
import core
8 from caffe2.python.dataio
import Reader
9 from caffe2.python.schema
import Scalar, Struct, data_type_for_dtype
14 Wrapper around operators for reading from text files. 16 def __init__(self, init_net, filename, schema, num_passes=1, batch_size=1):
18 Create op for building a TextFileReader instance in the workspace. 21 init_net : Net that will be run only once at startup. 22 filename : Path to file to read from. 23 schema : schema.Struct representing the schema of the data. 24 Currently, only support Struct of strings. 25 num_passes : Number of passes over the data. 26 batch_size : Number of rows to read at a time. 28 assert isinstance(schema, Struct),
'Schema must be a schema.Struct' 29 for name, child
in schema.get_children():
30 assert isinstance(child, Scalar), (
31 'Only scalar fields are supported in TextFileReader.')
33 data_type_for_dtype(dtype)
for dtype
in schema.field_types()]
34 Reader.__init__(self, schema)
35 self.
_reader = init_net.CreateTextFileReader(
38 num_passes=num_passes,
39 field_types=field_types)
44 Create op for reading a batch of rows. 46 blobs = net.TextFileReaderRead(
48 len(self.schema().field_names()),
53 is_empty = net.IsEmpty(
58 return (is_empty, blobs)
def __init__(self, init_net, filename, schema, num_passes=1, batch_size=1)
def ScopedBlobReference(name, args, kwargs)