keras使用、函数功能
-
#1. keras.engine.input_layer.Input()
| def Input(shape=None, batch_shape=None, | |
| name=None, dtype=None, sparse=False, | |
| tensor=None): |
用来实例化一个keras tensor
-
#2. class Dense(Layer):
keras.layers.Dense(units, 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)
| def __init__(self, units, | |
| 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, | |
| **kwargs): |
Dense 是一个类,用来regular densely-connected NN layer.
#3. from keras.models import Sequential, Model
#4. from keras.utils.np_utils import to_categorical
categorical_labels = to_categorical(int_labels, num_classes=None)
说明:
例如如果你有10个类别,每一个样本的标签应该是一个10维的向量,该向量在对应有值的索引位置为1其余为0。
EXAMPLE:
假设y_test为100x1的向量,100表示样本数,标签为标量,这时候将标签扩充为10维的向量,即:y_test为100x10。10维向量中,值为1表示这个样本属于这个类别,其他9个地方的值都为0。
y_test = to_categorical(y_test, 10)
#5. tensorflow的Tensor变量好像不能显示
example:
import tensorflow as tf
v1=tf.zeros([2,2]) # v1为Tensor类型
v3=tf.Session().run(v1) # 将Tensor变量v1 转换为 v3 ,v3为array类的对象
#6. numpy.array的array为一个类,别名为:ndarray
#7.np.array([1, 2, 3])
这个既不是行向量也不是列向量,它只是一个维度为3的向量
#8 将numpy数据转换为tensor
虽然TensorFlow网络在输入Numpy数据时会自动转换为Tensor来处理,但是我们自己也可以去显式的转换:
data_tensor= tf.convert_to_tensor(data_numpy)

浙公网安备 33010602011771号