当前位置: 首页>>代码示例>>Python>>正文


Python losses.CrossEntropyLoss方法代码示例

本文整理汇总了Python中losses.CrossEntropyLoss方法的典型用法代码示例。如果您正苦于以下问题:Python losses.CrossEntropyLoss方法的具体用法?Python losses.CrossEntropyLoss怎么用?Python losses.CrossEntropyLoss使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在losses的用法示例。


在下文中一共展示了losses.CrossEntropyLoss方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: build_graph

# 需要导入模块: import losses [as 别名]
# 或者: from losses import CrossEntropyLoss [as 别名]
def build_graph(reader,
                model,
                input_data_pattern,
                label_loss_fn=losses.CrossEntropyLoss(),
                batch_size=1000,
                transformer_class=feature_transform.DefaultTransformer):
  
  video_id, model_input_raw, labels_batch, num_frames = (
      get_input_data_tensors(
          reader,
          input_data_pattern,
          batch_size=batch_size,
          num_readers=FLAGS.num_readers))

  feature_transformer = transformer_class()
  model_input, num_frames = feature_transformer.transform(model_input_raw, num_frames=num_frames)

  with tf.name_scope("model"):
    if FLAGS.noise_level > 0:
      noise_level_tensor = tf.placeholder_with_default(0.0, shape=[], name="noise_level")
    else:
      noise_level_tensor = None

    if FLAGS.dropout:
      keep_prob_tensor = tf.placeholder_with_default(1.0, shape=[], name="keep_prob")
      result = model.create_model(
          model_input,
          num_frames=num_frames,
          vocab_size=reader.num_classes,
          labels=labels_batch,
          dropout=FLAGS.dropout,
          keep_prob=keep_prob_tensor,
          noise_level=noise_level_tensor)
    else:
      result = model.create_model(
          model_input,
          num_frames=num_frames,
          vocab_size=reader.num_classes,
          labels=labels_batch,
          noise_level=noise_level_tensor)

    print "result", result
    predictions = result["predictions"]

    tf.add_to_collection("predictions", predictions)
    tf.add_to_collection("video_id_batch", video_id)
    tf.add_to_collection("input_batch_raw", model_input_raw)
    tf.add_to_collection("input_batch", model_input)
    tf.add_to_collection("num_frames", num_frames)
    tf.add_to_collection("labels", tf.cast(labels_batch, tf.float32))
    if FLAGS.dropout:
      tf.add_to_collection("keep_prob", keep_prob_tensor)
    if FLAGS.noise_level > 0:
      tf.add_to_collection("noise_level", noise_level_tensor) 
开发者ID:wangheda,项目名称:youtube-8m,代码行数:56,代码来源:inference-sample-error.py


注:本文中的losses.CrossEntropyLoss方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。