相关疑难解决方法(0)

如何选择张量流中的交叉熵损失?

分类问题,例如逻辑回归或多项逻辑回归,优化了交叉熵损失.通常,交叉熵层遵循softmax层,其产生概率分布.

在tensorflow中,至少有十几种不同的交叉熵损失函数:

  • tf.losses.softmax_cross_entropy
  • tf.losses.sparse_softmax_cross_entropy
  • tf.losses.sigmoid_cross_entropy
  • tf.contrib.losses.softmax_cross_entropy
  • tf.contrib.losses.sigmoid_cross_entropy
  • tf.nn.softmax_cross_entropy_with_logits
  • tf.nn.sigmoid_cross_entropy_with_logits
  • ...

哪个只适用于二进制分类,哪个适用于多类问题?你何时应该使用sigmoid而不是softmax?如何在sparse功能与别人不同,为什么仅是它softmax

相关(更多数学导向)讨论:交叉熵丛林.

machine-learning neural-network logistic-regression tensorflow cross-entropy

76
推荐指数
3
解决办法
4万
查看次数

如何使用tf.estimator导入已保存的Tensorflow模型序列并预测输入数据

我使用tf.estimator .method export_savedmodel保存模型,如下所示:

export_dir="exportModel/"

feature_spec = tf.feature_column.make_parse_example_spec(feature_columns)

input_receiver_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)

classifier.export_savedmodel(export_dir, input_receiver_fn, as_text=False, checkpoint_path="Model/model.ckpt-400") 
Run Code Online (Sandbox Code Playgroud)

如何导入此保存的模型并用于预测?

tensorflow tensorflow-serving

20
推荐指数
1
解决办法
2万
查看次数

将Tensorflow图转换为使用Estimator,使用`sampled_softmax_loss`或`nce_loss`在损失函数中获取'TypeError:数据类型不被理解'

我试图将Tensorflow的官方基本word2vec实现转换为使用tf.Estimator.问题是当使用Tensorflow Estimators时,损失函数(sampled_softmax_lossnce_loss)会出错.它在原始实现中完美地运行.

这是Tensorflow的官方基本word2vec实现:

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/word2vec/word2vec_basic.py

以下是我实施此代码的Google Colab笔记本,该代码正常运行.

https://colab.research.google.com/drive/1nTX77dRBHmXx6PEF5pmYpkIVxj_TqT5I

这是Google Colab笔记本,我在其中更改了代码,因此它使用Tensorflow Estimator,它不起作用.

https://colab.research.google.com/drive/1IVDqGwMx6BK5-Bgrw190jqHU6tt3ZR3e

为方便起见,这里是我定义的Estimator版本的精确代码 model_fn

batch_size = 128
embedding_size = 128  # Dimension of the embedding vector.
skip_window = 1  # How many words to consider left and right.
num_skips = 2  # How many times to reuse an input to generate a label.
num_sampled = 64  # Number of negative examples to sample.

def my_model( features, labels, mode, params):

    with tf.name_scope('inputs'):
        train_inputs = features
        train_labels = labels …
Run Code Online (Sandbox Code Playgroud)

python tensorflow tensorflow-estimator

5
推荐指数
1
解决办法
331
查看次数