I am working on image dataset
I first resized all images
im_size1 = 128
im_size2 = 128
i = 0
for f, breed in tqdm(df_train.values):
if type(cv2.imread('train/{}.jpeg'.format(f)))==type(None):
continue
else:
img = cv2.imread('train/{}.jpeg'.format(f))
label = one_hot_labels[i]
x_train.append(cv2.resize(img, (im_size1, imt_size2)))
y_train.append(label)
i += 1
np.save('x_train2',x_train)
np.save('y_train2',y_train)
print('Done')
On the second run i passed Histogram of Gradient Feature Note: Model was same in both cases. Ran on different projects, got different results
i = 0
for f, breed in tqdm(df_train.values):
if type(cv2.imread('train/{}.jpeg'.format(f)))==type(None):
continue
else:
img = cv2.imread('train/{}.jpeg'.format(f))
label = one_hot_labels[i]
resizedImage = cv2.resize(img, (im_size1, im_size2))
hog_vec, hog_vis = feature.hog(resizedImage, visualize=True)
resizedImageVec = cv2.resize(hog_vec, (im_size1, im_size2))
x_train.append(resizedImageVec)
#np.concatenate(x_train, hog_vec[:])
y_train.append(label)
i += 1
np.save('x_train2hog',x_train)
np.save('y_train2hog',y_train)
print('Done')
Then configured the model like so
base_model = ResNet50(weights = None, include_top=False, input_shape=(im_size1, im_size2, 3))
# Add a new top layer
x = base_model.output
x = Flatten()(x)
x = Dropout(0.2)(x)
x = Dense(32, activation='relu')(x)
x = Dense(16, activation='relu')(x)
predictions = Dense(num_class, activation='softmax')(x)
# This is the model we will train
model = Model(inputs=base_model.input, outputs=predictions)
# First: train only the top layers (which were randomly initialized)
#for layer in base_model.layers:
# layer.trainable = False
model.compile(loss='categorical_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])
callbacks_list = [keras.callbacks.EarlyStopping(monitor='val_acc', verbose=1)]
model.summary()
Now my professor has asked me this.
"Train last layer using images, then train last layer using features (different representation of images). Concatenate these two layers, and then train one more layer."
Please guide me how can i accomplish this