Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNN retraining #7

Open
raresct opened this issue May 30, 2017 · 0 comments
Open

CNN retraining #7

raresct opened this issue May 30, 2017 · 0 comments

Comments

@raresct
Copy link
Owner

raresct commented May 30, 2017

The idea is to see whether training a new NN on top of existing features (or even the original image) works for the regression problem.

E.g. for resnet50

import numpy as np
from keras.applications import ResNet50
from keras.layers import Dense, Flatten, Dropout, Input
from keras.models import Model

def custom_fc():
    inputs = Input(shape=(1,1,2048))
    x = Flatten()(inputs)
    x = Dropout(0.5, seed=1234)(x)
    x = Dense(256, activation='relu')(x)
    x = Dropout(0.1, seed=1234)(x)
    x = Dense(32, activation='relu')(x)
    outputs = Dense(1, activation='linear')(x)
    return Model(inputs=inputs, outputs=outputs)

r50 = ResNet50(weights='imagenet',include_top=False,input_shape=(224,224,3))

x_train = np.random.random((10, 224, 224,3))
y_train = 100*np.random.random((10, 1))

x_train_r50 = r50.predict(x_train)
print x_train_r50.shape

model = custom_fc()
model.compile(optimizer='rmsprop', loss='mse')

model.fit(x_train_r50, y_train, epochs=100, batch_size=1)

y_pred = model.predict(x_train_r50)

print y_train
print '*'*30
print y_pred

Also try binning target variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant