Tensorflow2 implements various problems encountered in DenseNet classification CIFAR10

tf.keras.layers.Input() input layer analysis

layers.Input(
    shape=None,
    batch_size=None,
    name=None,
    dtype=None,
    sparse=False,
    tensor=None,
    ragged=False,
    **kwargs,
)

Role:
The first layer used to build the network - the input layer, this layer will tell the network what the size of our input is, which is very important. For example, use Model(input=x, output=y) to build a network. This construction method is very common and has a wide range of uses.
Parameter meaning:
shape: input shape, tuple type. Batch_size is not included; tuple elements can be None type data, which means unknown or arbitrary. Generally, None is not used here. batch_size
: Declare the input batch_size size, which is generally used in prediction. It does not need to be declared during training, and it will be used during fit The statement, that is, the dataset type data declares the batch_size
name: give the layers a name, and the same name cannot appear in the entire network. If name=None, the system will automatically create a name for the layer.
dtype: data type, in most cases, the data type we need is tf.float32, because float32 operation is faster when the precision is satisfied.
reference blog

ZeroPadding2D

keras.layers.ZeroPadding2D(padding=(1, 1), data_format=None)

Here it means that 1 is added to the top and bottom, so the number of rows is +2; 1 is added to the left and right, so the number of columns is +2.

When the input is an image, that is, the zero padding layer when the input is 2D, you can add rows and columns represented by 0 to the top, bottom, left, and right of the image tensor

parameter:

  1. padding : integer, or tuple of 2 integers, or 2-tuple of 2 integers.
  • If integer: will apply the same symmetric padding to width and height.
  • If a tuple of 2 integers:
  • If integer:: Interpreted as height and 2 different symmetric clipping values ​​for height: (symmetric_height_pad, symmetric_width_pad).
  • If a 2-tuple of 2 integers: Interpreted as ((top_pad, bottom_pad), (left_pad, right_pad)).
  1. data_format: string, one of channels_last (default) or channels_first, indicating the order of dimensions in the input. channels_last corresponds to the input size (batch, height, width, channels), and channels_first corresponds to the input size (batch, channels, height, width). It defaults to the image_data_format value found in the Keras configuration file ~/.keras/keras.json. If you never set it, "channels_last" will be used.

reference blog

keras.layers.convolutional.Conv2D

keras.layers.convolutional.Conv2D(filters, # 卷积核数目
                                  kernel_size, # 过滤器的大小
                                  strides(1,1),  # 步长
                                  padding='valid', # 边界处理
                                  data_format=None, 
                                  dilation_rate=(1,1), 
                                  activation=None, # 激活函数
                                  use_bias=True, #是否使用偏置量,布尔值
                                  kernel_initializer='glorot_uniform',
                                  bias_initializer='zeros',
                                  kernel_regularizer=None,
                                  bias_regularizer=None,
                                  activity_regularizer=None,
                                  kernel_constraint=None,
                                  bias_constraint=None)

解决(‘You must install pydot (pip install pydot) and install graphviz (see…) ‘, ‘for plot_model…

tf.keras.utils.plot_model(resnet50)

报错:('Failed to import pydot. You must pip install pydot and install graphviz (https://graphviz.gitlab.io/download/), ', ‘for pydotprint to work.’)
Solution

pip install pydot
pip install graphviz
pip install pydotplus

Some people say that graphviz cannot be installed with pip, and I have been using conda to install it since then:conda install graphviz

reference blog

Guess you like

Origin blog.csdn.net/weixin_43845922/article/details/127589909