I am new to TensorFlow. I am looking for the help on the image recognition where I can train my own image dataset.
Is there any example for training the new dataset?
Training usually takes between 2-8 hours depending on the number of files and queued models for training.
If you are interested in how to input your own data in TensorFlow, you can look at this tutorial.
I've also written a guide with best practices for CS230 at Stanford here.
tf.data
) and with labelsWith the introduction of tf.data
in r1.4
, we can create a batch of images without placeholders and without queues. The steps are the following:
tf.data.Dataset
reading these filenames and labelstf.data.Dataset
which will yield the next batchThe code is:
# step 1 filenames = tf.constant(['im_01.jpg', 'im_02.jpg', 'im_03.jpg', 'im_04.jpg']) labels = tf.constant([0, 1, 0, 1]) # step 2: create a dataset returning slices of `filenames` dataset = tf.data.Dataset.from_tensor_slices((filenames, labels)) # step 3: parse every image in the dataset using `map` def _parse_function(filename, label): image_string = tf.read_file(filename) image_decoded = tf.image.decode_jpeg(image_string, channels=3) image = tf.cast(image_decoded, tf.float32) return image, label dataset = dataset.map(_parse_function) dataset = dataset.batch(2) # step 4: create iterator and final input tensor iterator = dataset.make_one_shot_iterator() images, labels = iterator.get_next()
Now we can run directly sess.run([images, labels])
without feeding any data through placeholders.
To sum it up you have multiple steps:
The simplest code would be:
# step 1 filenames = ['im_01.jpg', 'im_02.jpg', 'im_03.jpg', 'im_04.jpg'] # step 2 filename_queue = tf.train.string_input_producer(filenames) # step 3: read, decode and resize images reader = tf.WholeFileReader() filename, content = reader.read(filename_queue) image = tf.image.decode_jpeg(content, channels=3) image = tf.cast(image, tf.float32) resized_image = tf.image.resize_images(image, [224, 224]) # step 4: Batching image_batch = tf.train.batch([resized_image], batch_size=8)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With