# 菜鸟 深 学 的 逆袭 之 路 # day7

When jupyter imports files, directly using import cnn_utils cannot use the parameters, such as:

import matploblit.pyplot as plt
import cnn_utils
plt.imshow(X_train_orig[index])

An error will be reported here, showing that X_train_orig is not defined, because this is a parameter defined in cnn_utils and cannot be used directly here. The solution:

from cnn_utils import load_dataset
X_train_orig,Y_train_orig,X_test_orig,Y_test_orig,classes = load_dataset()

To solve the problem.

2. When tensorflow creates placeholders, if you don't know the number of a certain dimension, you can use None instead of the specific value.
3.tf.get_variable (name, shape, initializer): name is the name of the variable, shape is the dimension of the variable, and initializer is the method of variable initialization.
When initializer = tf.contrib.layers.xavier_initializer,
the function returns a Initialization procedure, this initializer is used to keep the gradient size of each layer almost the same.
4. Regarding the difference between tf.get_variable and tf.variable, there are two websites that are quite wide, you can refer to it:
https://www.cnblogs.com/wf-ml/p/9721027.html
https: // blog .csdn.net / MrR1ght / article / details / 81228087? depth_1-utm_source = distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1 & utm_source = distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1
5.tensorflow can Directly used functions:

tf.nn.conv2d(X,W1,strides=[1,s,s,1],padding='SAME')

Given input X XX and a set of filters W1 W1W1, this function will automatically use W1 W1W1 to convolve X XX. The third input parameter is ** [1, s, s, 1] ** means For the input (m, n_H_prev, n_W_prev, n_C_prev), the step of each slide.

tf.nn.max_pool(A, ksize = [1,f,f,1], strides = [1,s,s,1], padding = 'SAME')

Given the input X XX, the function will use a window of size (f, f) and step (s, s) to slide it to the maximum value

tf.nn.relu(Z1) #计算Z1的ReLU激活

tf.contrib.layers.flatten(P)  #给定一个输入P,此函数将会把每个样本转化成一维的向量,然后返回一个tensor变量,其维度为(batch_size,k)

tf.contrib.layers.fully_connected(F, num_outputs)  #给定一个已经一维化了的输入F,此函数将会返回一个由全连接层计算过后的输出。

#使用tf.contrib.layers.fully_connected(F, num_outputs)的时候,全连接层会自动初始化权值且在你训练模型的时候它也会一直参与,所以当我们初始化参数的时候我们不需要专门去初始化它的权值。
tf.nn.softmax_cross_entropy_with_logits(logits = Z3 , lables = Y) #计算softmax的损失函数。这个函数既计算softmax的激活,也计算其损失

tf.reduce_mean #计算的是平均值,使用它来计算所有样本的损失来得到总成本。

6. Regarding the problem of axis = 0 and 1, it is more interesting to encounter an explanation: axis = 0 is indeed the meaning of the line, I also struggled for a long time, until I came across an excellent explanation: axis = 0 means " "By row" is actually an operation on each column. For the same reason, axis = 1 operates on each column, that is, on each row. I think it can be compared with the pixel matrix h * w of the image. The direction of the first coordinate axis h is downward, and the direction of the second coordinate axis w is right.
7.tf.argmax:
tf.argmax (vector, 1): returns the index number of the maximum value in the vector, if the vector is a vector, then returns a value, if it is a matrix, then returns a vector, Each dimension of this vector is the index number of the largest element of the corresponding matrix row.

8.equal, equal meaning. As the name implies, this function is used to determine equality.
Tf.equal (A, B) is to compare the equal elements of these two matrices or vectors. If they are equal, then return True, anyway return False, the matrix dimension and A It ’s the same
because of the element-by-element comparison, so the x and y dimensions should be the same

9.tf.cast (): The function is mainly used for tensor data type conversion

Published 31 original articles · Likes0 · Visits 683

Guess you like

Origin blog.csdn.net/ballzy/article/details/105299089