【问题标题】:Tensorflow applying operations inside a model: FailedPreconditionErrorTensorFlow 在模型中应用操作:FailedPreconditionError
【发布时间】:2020-02-28 17:37:47
【问题描述】:

假设我有一个 CNN 模型,它以类似 Unet 的方式输出 N 个概率图作为与输入图像相同大小的掩码。然后,我想在每个掩码上应用最小二乘拟合,以获取函数的系数作为输出,并使用这些系数来计算我的模型损失。

def unet_model(...)
    # init unet model
    ...
    ...
    # final layer
    mask_out = layers.Conv2D(output_channels, (1,1), activation='softmax')(conv9)

    # start applying e.g least squares fit here
    eq_list = tf.Variable((x_map, y_map, mask_out))
    transp = tf.transpose(a)
    ...

当我初始化模型时,transp 会得到以下错误。我已经在别处测试了最小二乘拟合操作。

FailedPreconditionError: Error while reading resource variable _AnonymousVar1423 from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/_AnonymousVar1423/N10tensorflow3VarE does not exist. name: transpose/

我有一些假设,例如转置无法处理批量大小的占位符轴,但通常对此一无所知。

【问题讨论】:

    标签: python tensorflow keras


    【解决方案1】:

    在添加每个变量之前,我需要确保 x_map 和 y_map 也通过使用轴 -1 扩展暗淡来进行批处理

    【讨论】:

    • hmm 这似乎不正确,我将代码修复为现在可以正确接受批次,但现在看来 tf.Variable 没有初始化
    猜你喜欢
    • 1970-01-01
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2017-12-12
    相关资源
    最近更新 更多