-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoneCNNfitting.py
96 lines (80 loc) · 2.18 KB
/
oneCNNfitting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from keras.layers import Input, Dense
from keras.models import Model
from keras.layers.core import Flatten, Dense, Dropout,Activation
from keras.layers.normalization import BatchNormalization as bn
from keras.layers.pooling import MaxPooling1D as pool
from keras.layers.convolutional import Conv1D as cnn1
import numpy as np
# This returns a tensor
inputs = Input(shape=(72,1))
import keras.utils
# a layer instance is callable on a tensor, and returns a tensor
x = cnn1(64,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = cnn1(64,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = pool()(x)
x = cnn1(128,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = cnn1(128,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = pool()(x)
x = cnn1(256,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = cnn1(256,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = cnn1(256,3)(inputs)
x = bn()(x)
x = Activation('relu')(x)
x = pool()(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = pool()(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = cnn1(512,3)(inputs)
# x = bn()(x)
# x = Activation('relu')(x)
# x = pool()(x)
x = Flatten()(x)
x = Dense(512)(x)
x = bn()(x)
x = Activation('relu')(x)
predictions = Dense(1, activation='linear')(x)
#make data
train_x = np.random.random((1000,72,1))
train_y = train_x.sum(axis=1)
# validation_x = np.random.random((100,2))
# validation_y = validation_x.sum(axis=1)
test_x = np.random.random((100,72,1))
test_y = test_x.sum(axis=1)
print(train_x.shape)
print(train_y.shape)
# This creates a model that includes
# the Input layer and three Dense layers
model = Model(input=inputs, output=predictions)
#打印模型
model.summary()
model.compile(optimizer='rmsprop',
loss='mean_squared_error',
metrics=['mae', 'acc'])
model.fit(train_x,train_y, validation_data=(test_x, test_y),
nb_epoch=40, batch_size=100)
# model.save_weights('/home/etcp/szx/flower_data/third_park_predict.h5')