def build_inputs(self): input_queue = inputs.prefetch_input_data( self.reader, self.config.input_file_pattern, batch_size=self.config.batch_size, values_per_shard=self.config.values_per_input_shard, input_queue_capacity_factor=self.config.input_queue_capacity_factor, num_reader_threads=self.config.num_input_reader_threads) assert self.config.num_preprocess_threads % 2 == 0 data = [] for thread_id in range(self.config.num_preprocess_threads): # thread serialized_example = input_queue.dequeue() # caption id sample, label, sentences_length = inputs.parse_example( serialized_example, sample_feature=self.config.sample_feature, label_feature=self.config.label_feature, sentences_length_feature=self.config.sentences_length_feature) # sample = data_preprocess(sample, sentences_length) data.append([sample, label, sentences_length]) # mutil threads preprocessing the image queue_capacity = (2 * self.config.num_preprocess_threads * self.config.batch_size) # pipe for batch data #size: samples:[batch_size,sentence_num,sentence_len], labels:[batch_size],sentences_length:[batch_size,sentences_num] samples, labels, sentences_length = inputs.batch_with_dynamic_pad( data, batch_size=self.config.batch_size, queue_capacity=queue_capacity)
def build_inputs(self): """Input prefetching, preprocessing and batching. Outputs: self.images self.input_seqs self.target_seqs (training and eval only) self.input_mask (training and eval only) """ if self.mode == "inference": # In inference mode, images and inputs are fed via placeholders. image_feed = tf.placeholder(dtype=tf.string, shape=[], name="image_feed") input_feed = tf.placeholder(dtype=tf.int64, shape=[None], # batch_size name="input_feed") # Process image and insert batch dimensions. images = tf.expand_dims(self.process_image(image_feed), 0) input_seqs = tf.expand_dims(input_feed, 1) # No target sequences or input mask in inference mode. target_seqs = None input_mask = None else: # Prefetch serialized SequenceExample protos. input_queue = input_ops.prefetch_input_data( self.reader, self.config.input_file_pattern, is_training=self.is_training(), batch_size=self.config.batch_size, values_per_shard=self.config.values_per_input_shard, input_queue_capacity_factor=self.config.input_queue_capacity_factor, num_reader_threads=self.config.num_input_reader_threads) # Image processing and random distortion. Split across multiple threads # with each thread applying a slightly different distortion. assert self.config.num_preprocess_threads % 2 == 0 images_and_captions = [] for thread_id in range(self.config.num_preprocess_threads): serialized_sequence_example = input_queue.dequeue() encoded_image, caption = input_ops.parse_sequence_example( serialized_sequence_example, image_feature=self.config.image_feature_name, caption_feature=self.config.caption_feature_name) image = self.process_image(encoded_image, thread_id=thread_id) images_and_captions.append([image, caption]) # Batch inputs. queue_capacity = (2 * self.config.num_preprocess_threads * self.config.batch_size) images, input_seqs, target_seqs, input_mask = ( input_ops.batch_with_dynamic_pad(images_and_captions, batch_size=self.config.batch_size, queue_capacity=queue_capacity)) self.images = images self.input_seqs = input_seqs self.target_seqs = target_seqs self.input_mask = input_mask
def read_inputs(self): if self.mode == 'inference': image_feed = tf.placeholder(dtype=tf.string, shape=[], name="image_feed") input_feed = tf.placeholder(dtype=tf.int64, shape=[None], name="input_feed") images = tf.expand_dims( image_processing.process_image(image_feed, is_training=False, height=299, width=299, thread_id=0, image_format='jpeg'), 0) input_seqs = tf.expand_dims(input_feed, 1) target_seqs = None input_mask = None else: input_queue = inputs_ops.prefetch_input_data( self.reader, file_pattern=self.input_file_pattern, # Must be given as input is_training=True, batch_size=32, values_per_shard=2300, input_queue_capacity_factor=2, num_reader_threads=1) images_and_captions = [] for thread_id in range(4): serialized_sequence_example = input_queue.dequeue() encoded_image, caption = inputs_ops.parse_sequence_example( serialized_sequence_example, image_feature="image/data", caption_feature="image/caption_ids") image = image_processing.process_image(encoded_image, is_training=False, height=299, width=299, thread_id=thread_id, image_format="jpeg") images_and_captions.append([image, caption]) queue_capacity = (2 * 4 * self.batch_size) images, input_seqs, target_seqs, input_mask = ( inputs_ops.batch_with_dynamic_pad( images_and_captions, batch_size=32, queue_capacity=queue_capacity)) self.images = images self.input_seqs = input_seqs self.target_seqs = target_seqs self.input_mask = input_mask
def build_inputs(self): input_queue = inputs.prefetch_input_data( self.reader, self.config.input_file_pattern, batch_size=self.config.batch_size, values_per_shard=self.config.values_per_input_shard, input_queue_capacity_factor=self.config. input_queue_capacity_factor, num_reader_threads=self.config.num_input_reader_threads, is_training=self.is_training()) assert self.config.num_preprocess_threads % 2 == 0 data = [] for thread_id in range(self.config.num_preprocess_threads): # thread serialized_example = input_queue.dequeue() # caption id sample, label, sentences_length = inputs.parse_example( serialized_example, sample_feature=self.config.sample_feature, label_feature=self.config.label_feature, sentences_length_feature=self.config.sentences_length_feature) def data_preprocess(sample, sentences_length): # sample,sentences_length partition_num = sentences_length.shape[0] partition = [] for i, sentence_length in enumerate(sentences_length): partition.extend(np.ones(sentence_length) * i) return tf.dynamic_partition(sample, partition, partition_num) sample = data_preprocess(sample, sentences_length) data.append([sample, label, sentences_length]) # mutil threads preprocessing the image queue_capacity = (2 * self.config.num_preprocess_threads * self.config.batch_size) # pipe for batch data # size: samples:[batch_size,sentence_num,sentence_len], labels:[batch_size],sentences_length:[batch_size,sentences_num] self.samples, self.labels, self.sentences_length = inputs.batch_with_dynamic_pad( data, batch_size=self.config.batch_size, queue_capacity=queue_capacity)
def build_input(self): if self.config.mode == "inference": input_seqs = Input(shape=(1,), dtype='int32') images = Input(shape=(self.config.image_height, self.config.image_width,3,), dtype='float32') else: # Prefetch serialized SequenceExample protos. input_queue = input_ops.prefetch_input_data( self.reader, self.config.input_file_pattern, is_training=self.config.is_training(), batch_size=self.config.batch_size, values_per_shard=self.config.values_per_input_shard, input_queue_capacity_factor=self.config.input_queue_capacity_factor, num_reader_threads=self.config.num_input_reader_threads) # Image processing and random distortion. Split across multiple threads # with each thread applying a slightly different distortion. assert self.config.num_preprocess_threads % 2 == 0 images_and_captions = [] for thread_id in range(self.config.num_preprocess_threads): serialized_sequence_example = input_queue.dequeue() encoded_image, caption = input_ops.parse_sequence_example( serialized_sequence_example, image_feature=self.config.image_feature_name, caption_feature=self.config.caption_feature_name) image = self.process_image(encoded_image, thread_id=thread_id) images_and_captions.append([image, caption]) # Batch inputs. queue_capacity = (2 * self.config.num_preprocess_threads * self.config.batch_size) images, input_seqs, target_seqs, input_mask = ( input_ops.batch_with_dynamic_pad(images_and_captions, batch_size=self.config.batch_size, queue_capacity=queue_capacity)) self.target_seqs = target_seqs self.input_mask = input_mask self.images = images self.input_seqs = input_seqs
def build_inputs(self): """Input prefetching, preprocessing and batching. Outputs: self.images self.input_seqs self.target_seqs (training and eval only) self.input_mask (training and eval only) """ if self.mode == "inference": # In inference mode, images and inputs are fed via placeholders. image_feed = tf.placeholder(dtype=tf.string, shape=[], name="image_feed") input_feed = tf.placeholder(dtype=tf.int64, shape=[None], # batch_size name="input_feed") # Process image and insert batch dimensions. images = tf.expand_dims(self.process_image(image_feed), 0) input_seqs = tf.expand_dims(input_feed, 1) # No target sequences or input mask in inference mode. target_seqs = None input_mask = None else: # Prefetch serialized SequenceExample protos. input_queue = input_ops.prefetch_input_data( self.reader, self.config.input_file_pattern, is_training=self.is_training(), batch_size=self.config.batch_size, values_per_shard=self.config.values_per_input_shard, input_queue_capacity_factor=self.config.input_queue_capacity_factor, num_reader_threads=self.config.num_input_reader_threads) # Image processing and random distortion. Split across multiple threads # with each thread applying a slightly different distortion. assert self.config.num_preprocess_threads % 2 == 0 images_and_objects_and_captions = [] for thread_id in range(self.config.num_preprocess_threads): serialized_sequence_example = input_queue.dequeue() encoded_image,object_feature, caption = input_ops.parse_sequence_example( serialized_sequence_example, image_feature=self.config.image_feature_name, object_feature= self.config.image_object_feature_name, caption_feature=self.config.caption_feature_name) image = self.process_image(encoded_image, thread_id=thread_id) images_and_objects_and_captions.append([image,object_feature, caption]) # Batch inputs. queue_capacity = (2 * self.config.num_preprocess_threads * self.config.batch_size) images,objects_vector, input_seqs, target_seqs, input_mask = ( input_ops.batch_with_dynamic_pad(images_and_objects_and_captions, batch_size=self.config.batch_size, queue_capacity=queue_capacity)) self.images = images self.objects_vector = objects_vector self.input_seqs = input_seqs self.target_seqs = target_seqs self.input_mask = input_mask