1、可视化——Tensorboard实战
参考:https://blog.csdn.net/qq_41660119/article/details/105745045
如若输出每一层的参数,参考TF1.0代码
2、fine-tune-实战
参考:https://blog.csdn.net/qq_41660119/article/details/105943371
基本思想:不使用随机初始化来初始化参数,而是使用之前已经train好的一个模型来做参数初始化。
fine-tune三个步骤:
1. save models (third_party/myself):保存之前的模型
2. restore models checkpoint (断点恢复):用保存好的模型去做初始化,所以需要用模型中的参数来初始化神经网络。
3. keep some layers fixed.:在fine tune时需要保证底层的参数值不变,只改变上层的参数值。例如,在卷积神经网络中,可以使得卷积层不变,只调整全连接层。或者只有倒数第一二个卷积层重新训练,前N个卷积层不参与训练。
TF2.0模型保存待补充
3、activation-initializer-optimizer-实战
修改参数即可
TF1.0
conv3_2 = tf.layers.conv2d(conv3_1,
32, # output channel number
(3,3), # kernel size
padding = 'same',
activation = activation,
kernel_initializer = kernel_initializer,
name = 'conv3_2')
1、Activation如何进行修改
# activation: relu, sigmoid, tanh
2、initializer如何进行修改
# weight initializer: he, xavier, normal, truncated_normal
3、optimizer如何进行修改
# optimzier: Adam, Momentum, Gradient Descent.
4、图像增强api使用
下面只举个别例子,用到哪种具体参考API文档
resize: 缩放图像
img_path = './xiaozhan.jfif'
img = tf.io.read_file(img_path)
img = tf.image.decode_image(img)
print(img.shape)
resize_img = tf.image.resize_with_pad(img, 1350, 1350)
img_decoded_val = np.asarray(resize_img, np.uint8)
print(img_decoded_val.shape)
%matplotlib inline
imshow(img_decoded_val)
(450, 450, 3) (1350, 1350, 3)
Out[6]:
<matplotlib.image.AxesImage at 0x1a9df5ba128>
crop: 裁剪图像
name = './xiaozhan.jfif'
img_string = tf.io.read_file(name)
img_decoded = tf.image.decode_image(img_string)
padded_img = tf.image.pad_to_bounding_box(
img_decoded, 50, 100, 550, 650) #前两个是图片位置,后两个是画布
img_decoded_val = np.asarray(padded_img, np.uint8)
print(img_decoded_val.shape)
%matplotlib inline
imshow(img_decoded_val)
(550, 650, 3)
Out[7]:
<matplotlib.image.AxesImage at 0x1a9df724cf8>
name = './xiaozhan.jfif'
img_string = tf.io.read_file(name)
img_decoded = tf.image.decode_image(img_string)
padded_img = tf.image.crop_to_bounding_box(
img_decoded, 50, 50, 300, 300) #前两个是图片位置,后两个是画布
img_decoded_val = np.asarray(padded_img, np.uint8)
print(img_decoded_val.shape)
%matplotlib inline
imshow(img_decoded_val)
(300, 300, 3)
Out[16]:
<matplotlib.image.AxesImage at 0x1a9e31804e0>
flip: 翻转图像
name = './xiaozhan.jfif'
img_string = tf.io.read_file(name)
img_decoded = tf.image.decode_image(img_string)
flipped_img = tf.image.flip_left_right(img_decoded)
img_decoded_val = np.asarray(flipped_img, np.uint8)
print(img_decoded_val.shape)
%matplotlib inline
imshow(img_decoded_val)
(450, 450, 3)
Out[20]:
<matplotlib.image.AxesImage at 0x1a9e3244eb8>
brightness & contrast: 改变光照 && 对比度
name = './xiaozhan.jfif'
img_string = tf.io.read_file(name)
img_decoded = tf.image.decode_image(img_string)
new_img = tf.image.adjust_brightness(img_decoded, 0.5)
img_decoded_val = np.asarray(new_img, np.uint8)
print(img_decoded_val.shape)
%matplotlib inline
imshow(img_decoded_val)
(450, 450, 3)
Out[22]:
<matplotlib.image.AxesImage at 0x1a9e33186a0>
批归一化实战
参考:https://blog.csdn.net/qq_41660119/article/details/105746496
归一化的目的是为了加速训练,促进收敛,提高最终效果。主要是加速训练。所以如果是都收敛的话,那么归一化后的应该比不归一化的更快收敛,且最后效果能好一点点。但是,如果你的训练时间有限,比如只能x步,那么x越小,归一化的好处就越明显。
BN跟数据归一化是不冲突的,BN是在网络中间层输出的激活值上去做归一化,而数据归一化则是在数据上做的。