You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
* Update check_tfrecords to use new dataset load function.
* Add tfrecord_dir to create_tfrecords output.
* Restructure test image directory to match expected format.
* Feature/dataclass (#44)
* Added data classes for types.
* Checking in progress.
* Checking in more changes.
* Converted types to classes and refactored schema into OO pattern.
* Changed OrderedDict import to support py3.6.
* Changed OrderedDict import to support py3.6.
* Updated setup.py for version.
* fixing setup.py
* Patched requirements and setup.
* Addressed comments in code review.
* Addressed code comments round 2.
* refactored IMAGE_CSV_SCHEMA.
* Merged check_test.py from dev
Co-authored-by: Carlos Ezequiel <[email protected]>
* Feature/structured data tutorial (#45)
* Converted types to classes and refactored schema into OO pattern.
* Add tutorial on structured data conversion.
This changes types.FloatInput to use tf.float32 for its feature_spec
attribute to address potential incompatibility with using tf.float64
type in TensorFlow Transform.
Co-authored-by: Mike Bernico <[email protected]>
* Update structured data tutorial to use output dir.
* Clarify need for proper header when using create_tfrecords. Fixes#47.
* Clean up README and update image directory notebook.
* Feature/test image dir (#49)
* Restructure test image directory to match expected format.
* Clean up README and update image directory notebook.
* Fix minor issues
* Add an explicit error message for missing train split
* Configure automated tests for Jupyter notebooks.
* Add convert_and_load function.
Also refactor create_tfrecords to convert.
* Refactor check and common modules to utils.
* Add test targets for py files and notebooks.
* Feature/convert and load (#55)
* Add convert_and_load function.
Also refactor create_tfrecords to convert.
* Refactor check and common modules to utils.
* Add test targets for py files and notebooks.
* Update version in setup.py and release notes.
* Fix issues with GCS path parsing.
Co-authored-by: Mike Bernico <[email protected]>
Co-authored-by: Sergii Khomenko <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+95-94Lines changed: 95 additions & 94 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ TFRecorder can convert any Pandas DataFrame or CSV file into TFRecords. If your
9
9
[Release Notes](RELEASE.md)
10
10
11
11
## Why TFRecorder?
12
-
Using the TFRecord storage format is important for optimal machine learning pipelines and getting the most from your hardware (in cloud or on prem). The TFRecorder project started inside [Google Cloud AI Services](https://cloud.google.com/consulting) when we realized we were writing TFRecord conversion code over and over again.
12
+
Using the TFRecord storage format is important for optimal machine learning pipelines and getting the most from your hardware (in cloud or on prem). The TFRecorder project started inside [Google Cloud AI Services](https://cloud.google.com/consulting) when we realized we were writing TFRecord conversion code over and over again.
13
13
14
14
When to use TFRecords:
15
15
* Your model is input bound (reading data is impacting training time).
This format looks like a Pandas DataFrame or CSV formatted as:
201
202
202
203
| split | image_uri | label |
@@ -205,139 +206,139 @@ This format looks like a Pandas DataFrame or CSV formatted as:
205
206
206
207
where:
207
208
*`split` can take on the values TRAIN, VALIDATION, and TEST
208
-
*`image_uri` specifies a local or Google Cloud Storage location for the image file.
209
-
*`label` can be either a textbased label that will be integerized or integer
209
+
*`image_uri` specifies a local or Google Cloud Storage location for the image file.
210
+
*`label` can be either a text-based label that will be integerized or integer
210
211
211
212
## Flexible Schema
212
213
213
-
TFRecorder's flexible schema system allows you to use any schema you want for your input data. To support any input data schema, provide a schema map to TFRecorder. A TFRecorder schema_map creates a mapping between your dataframe column names and their types in the resulting
214
-
TFRecord.
214
+
TFRecorder's flexible schema system allows you to use any schema you want for your input data.
215
215
216
-
### Creating and using a schema map
217
-
A schema map is a Python dictionary that maps DataFrame column names to [supported
218
-
TFRecorder types.](#Supported-types)
216
+
For example, the default image CSV schema input can be defined like this:
217
+
```python
218
+
import pandas as pd
219
+
import tfrecorder
220
+
from tfrecorder import input_schema
221
+
from tfrecorder import types
219
222
220
-
For example, the default image CSV input can be defined like this:
223
+
image_csv_schema = input_schema.Schema({
224
+
'split': types.SplitKey,
225
+
'image_uri': types.ImageUri,
226
+
'label': types.StringLabel
227
+
})
221
228
222
-
```python
223
-
from tfrecorder import schema
229
+
# You can then pass the schema to `tfrecorder.create_tfrecords`.
224
230
225
-
image_csv_schema = {
226
-
'split': schema.split_key,
227
-
'image_uri': schema.image_uri,
228
-
'label': schema.string_label
229
-
}
231
+
df = pd.read_csv(...)
232
+
df.tensorflow.to_tfr(
233
+
output_dir='gs://my/bucket',
234
+
schema_map=image_csv_schema,
235
+
runner='DataflowRunner',
236
+
project='my-project',
237
+
region='us-central1')
230
238
```
231
-
Once created a schema_map can be sent to TFRecorder.
239
+
240
+
### Flexible Schema Example
241
+
242
+
Imagine that you have a dataset that you would like to convert to TFRecords that
243
+
looks like this:
244
+
245
+
| split | x | y | label |
246
+
|-------|-------|------|-------|
247
+
| TRAIN | 0.32 | 42 |1 |
248
+
249
+
You can use TFRecorder as shown below:
232
250
233
251
```python
234
252
import pandas as pd
235
-
from tfrecorder import schema
236
253
import tfrecorder
254
+
from tfrecorder import input_schema
255
+
from tfrecorder import types
256
+
257
+
# First create a schema map
258
+
schema = input_schema.Schema({
259
+
'split': types.SplitKey,
260
+
'x': types.FloatInput,
261
+
'y': types.IntegerInput,
262
+
'label': types.IntegerLabel,
263
+
})
264
+
265
+
# Now call TFRecorder with the specified schema_map
237
266
238
267
df = pd.read_csv(...)
239
268
df.tensorflow.to_tfr(
240
269
output_dir='gs://my/bucket',
241
-
schema_map=schema.image_csv_schema,
270
+
schema=schema,
242
271
runner='DataflowRunner',
243
272
project='my-project',
244
273
region='us-central1')
245
274
```
275
+
After calling TFRecorder's `to_tfr()` function, TFRecorder will create an Apache beam pipeline, either locally or in this case
276
+
using Google Cloud's Dataflow runner. This beam pipeline will use the schema map to identify the types you've associated with
277
+
each data column and process your data using [TensorFlow Transform](https://www.tensorflow.org/tfx/transform/get_started) and TFRecorder's image processing functions to convert the data into into TFRecords.
246
278
247
279
### Supported types
248
-
TFRecorder's schema system supports several types, all listed below. You can use
249
-
these types by referencing them in the schema map. Each type informs TFRecorder how
250
-
to treat your DataFrame columns. For example, the schema mapping
251
-
`my_split_key: schema.SplitKeyType` tells TFRecorder to treat the column `my_split_key` as
252
-
type `schema.SplitKeyType` and create dataset splits based on it's contents.
253
280
254
-
#### schema.ImageUriType
255
-
* Specifies the path to an image. When specified, TFRecorder
256
-
will load the specified image and store the image as a [base64 encoded](https://docs.python.org/3/library/base64.html)
257
-
[tf.string](https://www.tensorflow.org/tutorials/load_data/unicode) in the key 'image'
258
-
along with the height, width, and image channels as integers using they keys 'image_height', 'image_width', and 'image_channels'.
259
-
* A schema can contain only one imageUriType
281
+
TFRecorder's schema system supports several types.
282
+
You can use these types by referencing them in the schema map.
283
+
Each type informs TFRecorder how to treat your DataFrame columns.
284
+
285
+
#### types.SplitKey
260
286
261
-
#### schema.SplitKeyType
262
287
* A split key is required for TFRecorder at this time.
263
288
* Only one split key is allowed.
264
-
* Specifies a split key that TFRecorder will use to partition the
289
+
* Specifies a split key that TFRecorder will use to partition the
265
290
input dataset on.
266
291
* Allowed values are 'TRAIN', 'VALIDATION, and 'TEST'
267
292
268
-
Note: If you do not want your data to be partitioned please include a split_key and
269
-
set all rows to TRAIN.
293
+
Note: If you do not want your data to be partitioned, include a column with
294
+
`types.SplitKey` and set all the elements to `TRAIN`.
295
+
296
+
#### types.ImageUri
297
+
298
+
* Specifies the path to an image. When specified, TFRecorder
299
+
will load the specified image and store the image as a [base64 encoded](https://docs.python.org/3/library/base64.html)
300
+
[tf.string](https://www.tensorflow.org/tutorials/load_data/unicode) in the key 'image'
301
+
along with the height, width, and image channels as integers using the keys 'image_height', 'image_width', and 'image_channels'.
302
+
* A schema can contain only one imageUri column
303
+
304
+
#### types.IntegerInput
270
305
271
-
#### schema.IntegerInputType
272
306
* Specifies an int input.
273
307
* Will be scaled to mean 0, variance 1.
274
308
275
-
#### schema.FloatInputType
309
+
#### types.FloatInput
310
+
276
311
* Specifies an float input.
277
312
* Will be scaled to mean 0, variance 1.
278
313
279
-
#### schema.CategoricalInputType
314
+
#### types.CategoricalInput
315
+
280
316
* Specifies a string input.
281
317
* Vocabulary computed and output integerized.
282
318
283
-
#### schema.IntegerLabelType
319
+
#### types.IntegerLabel
320
+
284
321
* Specifies an integer target.
285
322
* Not transformed.
286
323
287
-
#### schema.StringLabelType
324
+
#### types.StringLabel
325
+
288
326
* Specifies a string target.
289
327
* Vocabulary computed and *output integerized.*
290
328
291
-
### Flexible Schema Example
292
-
293
-
Imagine that you have a dataset that you would like to convert to TFRecords that
294
-
looks like this:
295
-
296
-
| split | x | y | label |
297
-
|-------|-------|------|-------|
298
-
| TRAIN | 0.32 | 42 |1 |
299
-
300
-
You can use TFRecorder as shown below:
301
-
302
-
```python
303
-
import pandas as pd
304
-
import tfrecorder
305
-
from tfrecorder import schema
306
-
307
-
# First create a schema map
308
-
schema_map = {
309
-
'split':schema.SplitKeyType,
310
-
'x':schema.FloatInputType,
311
-
'y':schema.IntegerInputType,
312
-
'label':schema.IntegerLabelType
313
-
}
314
-
315
-
# Now call TFRecorder with the specified schema_map
316
-
317
-
df = pd.read_csv(...)
318
-
df.tensorflow.to_tfr(
319
-
output_dir='gs://my/bucket',
320
-
schema_map=schema_map,
321
-
runner='DataflowRunner',
322
-
project='my-project',
323
-
region='us-central1')
324
-
```
325
-
After calling TFRecorder's to_tfr() function, TFRecorder will create an Apache beam pipeline, either locally or in this case
326
-
using Google Cloud's Dataflow runner. This beam pipeline will use the schema map to identify the types you've associated with
327
-
each data column and process your data using [TensorFlow Transform](https://www.tensorflow.org/tfx/transform/get_started) and TFRecorder's image processing functions to convert the data into into TFRecords.
328
-
329
329
## Contributing
330
330
331
-
Pull requests are welcome. Please see our [code of conduct](docs/code-of-conduct.md) and [contributing guide](docs/contributing.md).
331
+
Pull requests are welcome.
332
+
Please see our [code of conduct](docs/code-of-conduct.md) and [contributing guide](docs/contributing.md).
332
333
333
334
## Why TFRecorder?
334
-
Using the TFRecord storage format is important for optimal machine learning pipelines and getting the most from your hardware (in cloud or on prem).
335
+
336
+
Using the TFRecord storage format is important for optimal machine learning pipelines and getting the most from your hardware (in cloud or on prem).
335
337
336
338
TFRecords help when:
337
339
* Your model is input bound (reading data is impacting training time).
338
340
* Anytime you want to use tf.Dataset
339
341
* When your dataset can't fit into memory
340
342
341
-
342
-
In our work at [Google Cloud AI Services](https://cloud.google.com/consulting) we wanted to help our users spend their time writing AI/ML applications, and spend less time converting data.
343
-
343
+
Need help with using AI in the cloud?
344
+
Visit [Google Cloud AI Services](https://cloud.google.com/consulting).
0 commit comments