diff --git a/house_prices_estimation_example_image.py b/house_prices_estimation_example_image.py index 46c76ea44e22baf2385bba3fb07943f5bfd1b3ce..09ecba29b9961287af6e5ee27d22752734112d86 100644 --- a/house_prices_estimation_example_image.py +++ b/house_prices_estimation_example_image.py @@ -17,19 +17,19 @@ import matplotlib.pyplot as plt __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 inputs = Input(shape=(input_shape,input_shape,3)) # loop over the number of filters x = inputs 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 = BatchNormalization()(x) + # x = BatchNormalization()(x) x = MaxPooling2D()(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 is_regression: y = Dense(num_classes, activation="sigmoid",name='last_dense_reg')(x) diff --git a/house_prices_estimation_example_image_and_data.py b/house_prices_estimation_example_image_and_data.py index 7760c2ef94cb6dea4d0cbe016d9a36850c5ba9eb..f1d1c84f47ac9036c0f07cbd087bcbb26068611f 100644 --- a/house_prices_estimation_example_image_and_data.py +++ b/house_prices_estimation_example_image_and_data.py @@ -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 = [trainX_data,trainX_img['frontal_img']] - testX = [testX_data,testX_img['frontal_img']] + trainX = [trainX_data,trainX_img['bathroom_img']] + testX = [testX_data,testX_img['bathroom_img']] input_shape_data = trainX[0].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_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))] # y_data = model_data.layers[-2]#(input_data[0]) @@ -48,7 +48,8 @@ if __name__ == "__main__": y_img = model_img(input_data[1]) 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) # for layer in model_img.layers: @@ -56,11 +57,11 @@ if __name__ == "__main__": 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', metrics=['mean_absolute_percentage_error', 'mean_absolute_error', 'mean_squared_error'], optimizer=opt) 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) model.save('regression_model_combined.h5')