No project description provided
Project description
whaTFRecordsWriter
Overview
Are you having trouble saving your precious data into an easy format for training and testing? Well, you're in luck because with whaTFRecordsWriter
we are trying to minimize the effort required to simplify your dataset with TFRecord.
Installation
Python 3.6+ is required
pip install whaTFRecordsWriter
Example
To encode images to tfrecords, you can use this method:
filename = 'test.tfrecords'
my = wr.Writer(filename)
my.addfeature('image', wr.encode_bytes, preporcessing=wr.load_image)
my.write('test_data')
Note: Make sure that the given directory when writing has all the images that you want to store.
To extract the images you can do this:
raw_image_dataset = tf.data.TFRecordDataset(filename)
def _parse_image_function(example_proto):
# Parse the input tf.Example proto using the dictionary above.
img = tf.io.parse_single_example(example_proto, my.decoding_features)
img = img['image']
img = tf.image.decode_jpeg(img, channels=3)
# image = tf.image.resize_images(image, [224, 224])
# image /= 255.0 # normalize to [0,1] range
# img = tf.cast(img, tf.float32)
# img = (img / 127.5) - 1 # normalized to [-1, 1]
return img
parsed_image_dataset = raw_image_dataset.map(_parse_image_function)
c = 0
if not os.path.exists('test_prod'):
os.mkdir('test_prod')
for image in parsed_image_dataset.take(5):
im = Image.fromarray(image.numpy(), 'RGB')
c += 1
im.save('./test_prod/test_%d.png' % c)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file whaTFRecordsWriter-0.0.2.tar.gz
.
File metadata
- Download URL: whaTFRecordsWriter-0.0.2.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8931107a46c09622bf4a491717d20975233994c5e83b4f539ab3dbdbf6942bcf |
|
MD5 | 52f87de3e2e4c59d1423ce67216fd45b |
|
BLAKE2b-256 | 95fee4b0840787468336dc56e05c3c4575413fdc66f89b04ef12c04a30121fa4 |