tensor的tf.print出现问题(无法打印单个值)

2024-06-02 10:00:17 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的代码:https://github.com/Franco7Scala/RestrictedAreaImageAdversarialAttack/tree/master/src 您应该看到test_attack.py和l2_attack.py

现在我们可以进入问题,在l2_-attack-py的这个地方:

        mask = tf.ones((batch_size, image_size, image_size, num_channels), tf.float32)
        # Get input shapes
        modifier_shape = tf.shape(modifier)
        mask_shape = tf.shape(mask)
        # Make indices grid
        oo, ii, jj, kk = tf.meshgrid(tf.range(modifier_shape[0]), tf.range(modifier_shape[1]), tf.range(modifier_shape[2]), tf.range(modifier_shape[3]), indexing='ij')
        # Shift indices
        ii += y_window
        jj += x_window
        # Scatter update
        mask_to_apply = tf.tensor_scatter_nd_update(mask, tf.stack([oo, ii, jj, kk], axis=-1), modifier)
        tf.print(mask_to_apply)

当我做tf.print(mask_to_apply)时,我有这个输出:Tensor("TensorScatterUpdate:0", shape=(9, 28, 28, 1), dtype=float32)而不是张量中的值,我如何打印这些值


Tags: topyimagesizetfrangemaskii