CNN之前如何处理负值

How to handle negative values before CNN

我将根据表示体积值的图像生成我的训练和测试数据集。此图像包含 -25 到 75 的范围。我想在预处理步骤中忽略负值。谁能告诉我应该如何对待负值?有没有办法在不改变正像素值的情况下将负值传输为零或无数据?

我无法就 提出建议,如果 应该这样做,但是如果你想将所有负值变为 0,你可以使用 tf.maximum:

import tensorflow as tf

x = tf.random.uniform((10, 10), -25, 75, dtype=tf.int32)
<tf.Tensor: shape=(10, 10), dtype=int32, numpy=
array([[ 57, -11,  48,  43,  29,  21,  15,  42,  -9,  12],
       [ 18,  67,  -9, -21,   6,  27,  50,  -1,  72,  51],
       [  2,  22,  70,  49,  50, -10,  67,   4,  59, -10],
       [-13,  39,  60, -20, -15, -17,  51,  73, -23,  21],
       [ 28,   8,  48,  66, -13,  -3,  44,  35,  23,  45],
       [-24,  30,  16,  25,  34, -13,  24,  49,  50, -10],
       [-24,  25,  -1,  35,  67,  45,  27,   6,  65,   4],
       [ 20,  -5,  41, -14, -10,  40,  21,  69,  13,  14],
       [ 53,  -2,   6,   0, -13,  28,  11, -11,  29,  17],
       [ 15,  40,  61,  56,   3,  56,  12, -12,  19,   0]])>

神奇之处在于:

tf.maximum(x, 0)
<tf.Tensor: shape=(10, 10), dtype=int32, numpy=
array([[57,  0, 48, 43, 29, 21, 15, 42,  0, 12],
       [18, 67,  0,  0,  6, 27, 50,  0, 72, 51],
       [ 2, 22, 70, 49, 50,  0, 67,  4, 59,  0],
       [ 0, 39, 60,  0,  0,  0, 51, 73,  0, 21],
       [28,  8, 48, 66,  0,  0, 44, 35, 23, 45],
       [ 0, 30, 16, 25, 34,  0, 24, 49, 50,  0],
       [ 0, 25,  0, 35, 67, 45, 27,  6, 65,  4],
       [20,  0, 41,  0,  0, 40, 21, 69, 13, 14],
       [53,  0,  6,  0,  0, 28, 11,  0, 29, 17],
       [15, 40, 61, 56,  3, 56, 12,  0, 19,  0]])>