Skip to content

Commit 00b7342

Browse files
committed
cleaned up the extra spaces and comments
1 parent cb1f61d commit 00b7342

File tree

1 file changed

+0
-17
lines changed

1 file changed

+0
-17
lines changed

examples/hyperas_in_intermediate_fns.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
from hyperopt import Trials, STATUS_OK, tpe
1010
from hyperas import optim
1111
from hyperas.distributions import choice, uniform
12-
from sklearn.metrics import roc_auc_score
1312

1413
def euclidean_distance(vects):
1514
x, y = vects
1615
return K.sqrt(K.maximum(K.sum(K.square(x - y), axis=1, keepdims=True), K.epsilon()))
1716

18-
1917
def eucl_dist_output_shape(shapes):
2018
shape1, shape2 = shapes
2119
return (shape1[0], 1)
@@ -36,9 +34,7 @@ def create_pairs(x, digit_indices):
3634
labels += [1, 0]
3735
return numpy.array(pairs), numpy.array(labels)
3836

39-
4037
def create_base_network(input_shape,dense_filter1,dense_filter2,dense_filter3,dropout1,dropout2):
41-
4238
input = Input(shape=input_shape)
4339
x = Flatten()(input)
4440
x = Dense(dense_filter1, activation='relu')(x)
@@ -48,15 +44,11 @@ def create_base_network(input_shape,dense_filter1,dense_filter2,dense_filter3,dr
4844
x = Dense(dense_filter3, activation='relu')(x)
4945
return Model(input, x)
5046

51-
5247
def compute_accuracy(y_true, y_pred):
53-
5448
pred = y_pred.ravel() < 0.5
5549
return numpy.mean(pred == y_true)
5650

57-
5851
def accuracy(y_true, y_pred):
59-
6052
return K.mean(K.equal(y_true, K.cast(y_pred < 0.5, y_true.dtype)))
6153

6254
def process_data():
@@ -81,13 +73,10 @@ def data():
8173
return tr_pairs, tr_y, te_pairs, te_y,input_shape
8274

8375
def contrastive_loss(y_true, y_pred):
84-
8576
margin = 1
8677
return K.mean(y_true * K.square(y_pred) +
8778
(1 - y_true) * K.square(K.maximum(margin - y_pred, 0)))
8879

89-
90-
9180
def create_model(tr_pairs, tr_y, te_pairs, te_y,input_shape):
9281
epochs = 20
9382
dropout1 = {{uniform(0,1)}}
@@ -101,9 +90,6 @@ def create_model(tr_pairs, tr_y, te_pairs, te_y,input_shape):
10190
input_a = Input(shape=input_shape)
10291
input_b = Input(shape=input_shape)
10392

104-
# because we re-use the same instance `base_network`,
105-
# the weights of the network
106-
# will be shared across the two branches
10793
processed_a = base_network(input_a)
10894
processed_b = base_network(input_b)
10995

@@ -112,7 +98,6 @@ def create_model(tr_pairs, tr_y, te_pairs, te_y,input_shape):
11298

11399
model = Model([input_a, input_b], distance)
114100

115-
# train
116101
rms = RMSprop()
117102
model.compile(loss=contrastive_loss, optimizer=rms, metrics=[accuracy])
118103
model.fit([tr_pairs[:, 0], tr_pairs[:, 1]], tr_y,
@@ -121,7 +106,6 @@ def create_model(tr_pairs, tr_y, te_pairs, te_y,input_shape):
121106
verbose=1,
122107
validation_data=([te_pairs[:, 0], te_pairs[:, 1]], te_y))
123108

124-
# compute final accuracy on training and test sets
125109
y_pred = model.predict([tr_pairs[:, 0], tr_pairs[:, 1]])
126110
tr_acc = compute_accuracy(tr_y, y_pred)
127111
y_pred = model.predict([te_pairs[:, 0], te_pairs[:, 1]])
@@ -144,4 +128,3 @@ def create_model(tr_pairs, tr_y, te_pairs, te_y,input_shape):
144128
print("Evalutation of best performing model:")
145129
loss,te_acc = best_model.evaluate([te_pairs[:, 0], te_pairs[:, 1]], te_y)
146130
print("best prediction accuracy on test data %0.2f%%" % (100 * te_acc))
147-

0 commit comments

Comments
 (0)