小编Nic*_*ker的帖子

Tensorflow 一种多输出模型的自定义指标

我在文档中找不到信息,所以我在这里询问。

我有一个具有 3 个不同输出的多输出模型:

model = tf.keras.Model(inputs=[input], outputs=[output1, output2, output3])
Run Code Online (Sandbox Code Playgroud)

用于验证的预测标签是根据这 3 个输出构建的,仅形成一个,这是一个后处理步骤。用于训练的数据集是这 3 种中间输出的数据集,为了验证,我在标签数据集而不是 3 种中间数据上进行评估。

我想使用处理后处理以及与真实情况比较的自定义指标来评估我的模型。

我的问题是,在自定义指标的代码中,将y_pred是模型的 3 个输出的列表吗?

class MyCustomMetric(tf.keras.metrics.Metric):

  def __init__(self, name='my_custom_metric', **kwargs):
    super(MyCustomMetric, self).__init__(name=name, **kwargs)

  def update_state(self, y_true, y_pred, sample_weight=None):
    # ? is y_pred a list [batch_output_1, batch_output_2, batch_output_3] ? 

  def result(self):
    pass 

# one single metric handling the 3 outputs?
model.compile(optimizer=tf.compat.v1.train.RMSPropOptimizer(0.01),
              loss=tf.keras.losses.categorical_crossentropy,
              metrics=[MyCustomMetric()])

Run Code Online (Sandbox Code Playgroud)

python keras tensorflow tensorflow2.0

8
推荐指数
1
解决办法
2803
查看次数

AttributeError: 'Tensor' object has no attribute 'numpy' in Tensorflow 2.1

I am trying to convert the shape property of a Tensor in Tensorflow 2.1 and I get this error:

AttributeError: 'Tensor' object has no attribute 'numpy'
Run Code Online (Sandbox Code Playgroud)

I already checked that the output of tf.executing eagerly() is True,

A bit of context: I load a tf.data.Dataset from a TFRecords, then I apply a map. The maping function is trying to convert the shape property of one of the dataset sample Tensor to numpy:

def _parse_and_decode(serialized_example):
    """ parse and decode …
Run Code Online (Sandbox Code Playgroud)

python numpy tensorflow tensorflow2.x

6
推荐指数
1
解决办法
7357
查看次数

从 onnx 文件中查找输入形状

如何找到 onnx 模型的输入大小?我最终想从 python 编写脚本。

使用 tensorflow 我可以恢复图定义,从中找到输入候选节点,然后获取它们的大小。我可以用 ONNX(甚至更简单)做类似的事情吗?

谢谢

python onnx

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

带有剪切下溢的字符减法

有没有办法计算:

/** clipped(a - b) **/
unsigned char clipped_substract(unsigned char a, unsigned char b)
{
    return a > b ? a - b : 0;
}
Run Code Online (Sandbox Code Playgroud)

使用一些二进制操作而不是测试?

c c++ binary-operators

3
推荐指数
1
解决办法
95
查看次数