Python losses.CrossEntropyLoss() Examples
The following are 1
code examples of losses.CrossEntropyLoss().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
losses
, or try the search function
.
Example #1
Source File: inference-sample-error.py From youtube-8m with Apache License 2.0 | 4 votes |
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)