Skip to content
Snippets Groups Projects
Commit a48ab5b6 authored by Picon Ruiz, Artzai's avatar Picon Ruiz, Artzai
Browse files

another version

parent 44cc0f86
No related branches found
No related tags found
No related merge requests found
...@@ -17,19 +17,19 @@ import matplotlib.pyplot as plt ...@@ -17,19 +17,19 @@ import matplotlib.pyplot as plt
__author__ = 106360 __author__ = 106360
def generate_simple_cnn_regression_model(input_shape,n_blocks=2,weights='',is_regression=True,num_classes=1,freeze=False,remove_head=False): def generate_simple_cnn_regression_model(input_shape,n_blocks=3,weights='',is_regression=True,num_classes=1,freeze=False,remove_head=False):
# define the model input # define the model input
inputs = Input(shape=(input_shape,input_shape,3)) inputs = Input(shape=(input_shape,input_shape,3))
# loop over the number of filters # loop over the number of filters
x = inputs x = inputs
for n in range(n_blocks): for n in range(n_blocks):
x = Conv2D(16, (3, 3), padding="same",name='conv_%d' % n)(x) x = Conv2D(32, (3, 3), padding="same",name='conv_%d' % n)(x)
x = Activation("relu")(x) x = Activation("relu")(x)
x = BatchNormalization()(x) # x = BatchNormalization()(x)
x = MaxPooling2D()(x) x = MaxPooling2D()(x)
x= Flatten()(x) x= Flatten()(x)
x = Dense(6, activation="relu", name='pre_last_dense_reg')(x) x = Dense(16, activation="relu", name='pre_last_dense_reg')(x)
if not remove_head: if not remove_head:
if is_regression: if is_regression:
y = Dense(num_classes, activation="sigmoid",name='last_dense_reg')(x) y = Dense(num_classes, activation="sigmoid",name='last_dense_reg')(x)
......
...@@ -31,15 +31,15 @@ if __name__ == "__main__": ...@@ -31,15 +31,15 @@ if __name__ == "__main__":
(trainX_data,trainX_img, trainY, testX_data,testX_img,testY), normalizer = load_house_dataset_data(test_size=0.2,random_state=666,type=DatasetType.Both) (trainX_data,trainX_img, trainY, testX_data,testX_img,testY), normalizer = load_house_dataset_data(test_size=0.2,random_state=666,type=DatasetType.Both)
trainX = [trainX_data,trainX_img['frontal_img']] trainX = [trainX_data,trainX_img['bathroom_img']]
testX = [testX_data,testX_img['frontal_img']] testX = [testX_data,testX_img['bathroom_img']]
input_shape_data = trainX[0].shape[1] input_shape_data = trainX[0].shape[1]
input_shape_img = trainX[1].shape[1] input_shape_img = trainX[1].shape[1]
model_data = generate_simple_regression_model(input_shape_data, weights='regression_model_data.h5',remove_head=True) model_data = generate_simple_regression_model(input_shape_data, weights='regression_model_data.h5',remove_head=True)
model_img = generate_simple_cnn_regression_model(input_shape_img, weights='regression_model_image_pretrained.h5',remove_head=True) model_img = generate_simple_cnn_regression_model(input_shape_img, weights='regression_model_image_pretrained.h5',remove_head=False)
input_data = [Input(input_shape_data),Input((input_shape_img,input_shape_img,3))] input_data = [Input(input_shape_data),Input((input_shape_img,input_shape_img,3))]
# y_data = model_data.layers[-2]#(input_data[0]) # y_data = model_data.layers[-2]#(input_data[0])
...@@ -48,7 +48,8 @@ if __name__ == "__main__": ...@@ -48,7 +48,8 @@ if __name__ == "__main__":
y_img = model_img(input_data[1]) y_img = model_img(input_data[1])
y = Concatenate()([y_data, y_img]) y = Concatenate()([y_data, y_img])
y = Dense(32, activation='relu')(y) y = BatchNormalization()(y)
y = Dense(16, activation='relu')(y)
y = Dense(1,activation='sigmoid')(y) y = Dense(1,activation='sigmoid')(y)
# for layer in model_img.layers: # for layer in model_img.layers:
...@@ -56,11 +57,11 @@ if __name__ == "__main__": ...@@ -56,11 +57,11 @@ if __name__ == "__main__":
model = Model(input_data,y) model = Model(input_data,y)
opt = Adam(lr=1e-3, decay=1e-3/400) opt = Adam(lr=1e-3, decay=1e-3/250)
model.compile(loss='mean_absolute_error', model.compile(loss='mean_absolute_error',
metrics=['mean_absolute_percentage_error', 'mean_absolute_error', 'mean_squared_error'], metrics=['mean_absolute_percentage_error', 'mean_absolute_error', 'mean_squared_error'],
optimizer=opt) optimizer=opt)
model.summary() model.summary()
model = train_model(trainX, trainY, testX, testY, model, show_plot=True, epochs=400, batch_size=32) model = train_model(trainX, trainY, testX, testY, model, show_plot=True, epochs=2000, batch_size=32)
evaluate_regression_model(model, testX, testY, normalizer, show_plot=True) evaluate_regression_model(model, testX, testY, normalizer, show_plot=True)
model.save('regression_model_combined.h5') model.save('regression_model_combined.h5')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment