本文整理汇总了Python中im2txt.show_and_tell_model.ShowAndTellModel方法的典型用法代码示例。如果您正苦于以下问题:Python show_and_tell_model.ShowAndTellModel方法的具体用法?Python show_and_tell_model.ShowAndTellModel怎么用?Python show_and_tell_model.ShowAndTellModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类im2txt.show_and_tell_model
的用法示例。
在下文中一共展示了show_and_tell_model.ShowAndTellModel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_inputs
# 需要导入模块: from im2txt import show_and_tell_model [as 别名]
# 或者: from im2txt.show_and_tell_model import ShowAndTellModel [as 别名]
def build_inputs(self):
if self.mode == "inference":
# Inference mode doesn't read from disk, so defer to parent.
return super(ShowAndTellModel, self).build_inputs()
else:
# Replace disk I/O with random Tensors.
self.images = tf.random_uniform(
shape=[self.config.batch_size, self.config.image_height,
self.config.image_width, 3],
minval=-1,
maxval=1)
self.input_seqs = tf.random_uniform(
[self.config.batch_size, 15],
minval=0,
maxval=self.config.vocab_size,
dtype=tf.int64)
self.target_seqs = tf.random_uniform(
[self.config.batch_size, 15],
minval=0,
maxval=self.config.vocab_size,
dtype=tf.int64)
self.input_mask = tf.ones_like(self.input_seqs)
示例2: testBuildForTraining
# 需要导入模块: from im2txt import show_and_tell_model [as 别名]
# 或者: from im2txt.show_and_tell_model import ShowAndTellModel [as 别名]
def testBuildForTraining(self):
model = ShowAndTellModel(self._model_config, mode="train")
model.build()
self._checkModelParameters()
expected_shapes = {
# [batch_size, image_height, image_width, 3]
model.images: (32, 299, 299, 3),
# [batch_size, sequence_length]
model.input_seqs: (32, 15),
# [batch_size, sequence_length]
model.target_seqs: (32, 15),
# [batch_size, sequence_length]
model.input_mask: (32, 15),
# [batch_size, embedding_size]
model.image_embeddings: (32, 512),
# [batch_size, sequence_length, embedding_size]
model.seq_embeddings: (32, 15, 512),
# Scalar
model.total_loss: (),
# [batch_size * sequence_length]
model.target_cross_entropy_losses: (480,),
# [batch_size * sequence_length]
model.target_cross_entropy_loss_weights: (480,),
}
self._checkOutputs(expected_shapes)
示例3: testBuildForEval
# 需要导入模块: from im2txt import show_and_tell_model [as 别名]
# 或者: from im2txt.show_and_tell_model import ShowAndTellModel [as 别名]
def testBuildForEval(self):
model = ShowAndTellModel(self._model_config, mode="eval")
model.build()
self._checkModelParameters()
expected_shapes = {
# [batch_size, image_height, image_width, 3]
model.images: (32, 299, 299, 3),
# [batch_size, sequence_length]
model.input_seqs: (32, 15),
# [batch_size, sequence_length]
model.target_seqs: (32, 15),
# [batch_size, sequence_length]
model.input_mask: (32, 15),
# [batch_size, embedding_size]
model.image_embeddings: (32, 512),
# [batch_size, sequence_length, embedding_size]
model.seq_embeddings: (32, 15, 512),
# Scalar
model.total_loss: (),
# [batch_size * sequence_length]
model.target_cross_entropy_losses: (480,),
# [batch_size * sequence_length]
model.target_cross_entropy_loss_weights: (480,),
}
self._checkOutputs(expected_shapes)
示例4: testBuildForInference
# 需要导入模块: from im2txt import show_and_tell_model [as 别名]
# 或者: from im2txt.show_and_tell_model import ShowAndTellModel [as 别名]
def testBuildForInference(self):
model = ShowAndTellModel(self._model_config, mode="inference")
model.build()
self._checkModelParameters()
# Test feeding an image to get the initial LSTM state.
images_feed = np.random.rand(1, 299, 299, 3)
feed_dict = {model.images: images_feed}
expected_shapes = {
# [batch_size, embedding_size]
model.image_embeddings: (1, 512),
# [batch_size, 2 * num_lstm_units]
"lstm/initial_state:0": (1, 1024),
}
self._checkOutputs(expected_shapes, feed_dict)
# Test feeding a batch of inputs and LSTM states to get softmax output and
# LSTM states.
input_feed = np.random.randint(0, 10, size=3)
state_feed = np.random.rand(3, 1024)
feed_dict = {"input_feed:0": input_feed, "lstm/state_feed:0": state_feed}
expected_shapes = {
# [batch_size, 2 * num_lstm_units]
"lstm/state:0": (3, 1024),
# [batch_size, vocab_size]
"softmax:0": (3, 12000),
}
self._checkOutputs(expected_shapes, feed_dict)
示例5: build_model
# 需要导入模块: from im2txt import show_and_tell_model [as 别名]
# 或者: from im2txt.show_and_tell_model import ShowAndTellModel [as 别名]
def build_model(self, model_config):
model = show_and_tell_model.ShowAndTellModel(model_config, mode="inference")
model.build()
return model
示例6: run
# 需要导入模块: from im2txt import show_and_tell_model [as 别名]
# 或者: from im2txt.show_and_tell_model import ShowAndTellModel [as 别名]
def run():
"""Runs evaluation in a loop, and logs summaries to TensorBoard."""
# Create the evaluation directory if it doesn't exist.
eval_dir = FLAGS.eval_dir
if not tf.gfile.IsDirectory(eval_dir):
tf.logging.info("Creating eval directory: %s", eval_dir)
tf.gfile.MakeDirs(eval_dir)
g = tf.Graph()
with g.as_default():
# Build the model for evaluation.
model_config = configuration.ModelConfig()
model_config.input_file_pattern = FLAGS.input_file_pattern
model = show_and_tell_model.ShowAndTellModel(model_config, mode="eval")
model.build()
# Create the Saver to restore model Variables.
saver = tf.train.Saver()
# Create the summary operation and the summary writer.
summary_op = tf.summary.merge_all()
summary_writer = tf.summary.FileWriter(eval_dir)
g.finalize()
# Run a new evaluation run every eval_interval_secs.
while True:
start = time.time()
tf.logging.info("Starting evaluation at " + time.strftime(
"%Y-%m-%d-%H:%M:%S", time.localtime()))
run_once(model, saver, summary_writer, summary_op)
time_to_next_eval = start + FLAGS.eval_interval_secs - time.time()
if time_to_next_eval > 0:
time.sleep(time_to_next_eval)