keras layer 技巧/權重/層配置 查看

from keras.layers import Flatten, Dropout, Dense
from keras.models import Sequential

import tensorflow as tf
import keras.backend.tensorflow_backend as KTF

config = tf.ConfigProto()
config.gpu_options.allow_growth = True  # 不全部佔滿顯存, 按需分配
sess = tf.Session(config=config)
KTF.set_session(sess)  # 設置session


model = Sequential()
model.add(Flatten(input_shape=(2, 2, 1), name='Flatten_0', batch_size=None))
from keras.initializers import RandomNormal
initLY = RandomNormal(6,3,3)
model.add(Dense(5, activation='relu', kernel_initializer=initLY, name='Dense_1'))
model.add(Dense(3, activation='relu', name='Dense_2'))
model.add(Dropout(0.5, name='Dropout_3'))
model.add(Dense(1, activation='sigmoid', name='Densoe_4'))
model.summary()

len(model.layers)  # 一共有多個層  # model.layers.__len__()
model.layers[0].get_config()  # 返回的是一個字典
model.layers[0].get_weights()
Using TensorFlow backend.
2019-12-17 19:58:40.759979: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2019-12-17 19:58:40.762878: I tensorflow/stream_executor/platform/default/dso_loader.cc:42] Successfully opened dynamic library nvcuda.dll
2019-12-17 19:58:40.861092: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1640] Found device 0 with properties: 
name: GeForce GTX 1060 6GB major: 6 minor: 1 memoryClockRate(GHz): 1.8095
pciBusID: 0000:01:00.0
2019-12-17 19:58:40.861380: I tensorflow/stream_executor/platform/default/dlopen_checker_stub.cc:25] GPU libraries are statically linked, skip dlopen check.
2019-12-17 19:58:40.861922: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1763] Adding visible gpu devices: 0
2019-12-17 19:58:42.013833: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1181] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-12-17 19:58:42.014038: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1187]      0 
2019-12-17 19:58:42.014168: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1200] 0:   N 
2019-12-17 19:58:42.014802: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4712 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
WARNING:tensorflow:From D:\Anaconda3\envs\laste\lib\site-packages\keras\backend\tensorflow_backend.py:64: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
WARNING:tensorflow:From D:\Anaconda3\envs\laste\lib\site-packages\keras\backend\tensorflow_backend.py:497: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.
WARNING:tensorflow:From D:\Anaconda3\envs\laste\lib\site-packages\keras\backend\tensorflow_backend.py:1264: calling reduce_prod_v1 (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
WARNING:tensorflow:From D:\Anaconda3\envs\laste\lib\site-packages\keras\backend\tensorflow_backend.py:3613: The name tf.random_normal is deprecated. Please use tf.random.normal instead.
WARNING:tensorflow:From D:\Anaconda3\envs\laste\lib\site-packages\keras\backend\tensorflow_backend.py:3636: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.
WARNING:tensorflow:From D:\Anaconda3\envs\laste\lib\site-packages\keras\backend\tensorflow_backend.py:3019: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.
Instructions for updating:
Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
Flatten_0 (Flatten)          (None, 4)                 0         
_________________________________________________________________
Dense_1 (Dense)              (None, 5)                 25        
_________________________________________________________________
Dense_2 (Dense)              (None, 3)                 18        
_________________________________________________________________
Dropout_3 (Dropout)          (None, 3)                 0         
_________________________________________________________________
Densoe_4 (Dense)             (None, 1)                 4         
=================================================================
Total params: 47
Trainable params: 47
Non-trainable params: 0
_________________________________________________________________
Out[2]: []

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章