只需在TensorFlow中查找等效的np.std()来计算张量的标准偏差.
我正在创建一个像这样的张量:
tensorflow::Tensor a(tensorflow::DT_FLOAT, tensorflow::TensorShape());
Run Code Online (Sandbox Code Playgroud)
我知道如何填写标量值:
a.scalar<float>()() = 8.0;
Run Code Online (Sandbox Code Playgroud)
但我不知道如何填补像[1,4,2]那样的张量.
在http://cs231n.github.io/neural-networks-2/上提到,对于卷积神经网络,优选使用平均减法和归一化技术预处理数据.
我只是想知道如何使用Tensorflow最好地接近它.
平均减法
X -= np.mean(X)
Run Code Online (Sandbox Code Playgroud)
正常化
X /= np.std(X, axis = 0)
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用TensorFlow干净的方式(tf.train.shuffle_batch)处理我的输入数据,我从教程中收集的大部分代码都经过了一些细微的修改,例如decode_jpeg函数。
size = 32,32
classes = 43
train_size = 12760
batch_size = 100
max_steps = 10000
def read_and_decode(filename_queue):
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(
serialized_example,
# Defaults are not specified since both keys are required.
features={
'image/encoded': tf.FixedLenFeature([], tf.string),
'image/class/label': tf.FixedLenFeature([], tf.int64),
'image/height': tf.FixedLenFeature([], tf.int64),
'image/width': tf.FixedLenFeature([], tf.int64),
})
label = tf.cast(features['image/class/label'], tf.int32)
reshaped_image = tf.image.decode_jpeg(features['image/encoded'])
reshaped_image = tf.image.resize_images(reshaped_image, size[0], size[1], method = 0)
reshaped_image = tf.image.per_image_whitening(reshaped_image)
return reshaped_image, label
def inputs(train, batch_size, num_epochs):
subset = …Run Code Online (Sandbox Code Playgroud)