fchollet / deep-learning-models

Keras code and weights files for popular deep learning models.
MIT License
7.32k stars 2.46k forks source link

Train inception #19

Open kushia opened 8 years ago

kushia commented 8 years ago

Hi everyone, I'm trying to train the inception model from custom images. But I got one problems.. Here is the code I use `import os import numpy as np import pandas as pd from scipy.misc import imread from scipy.misc import imresize from inception_v3 import InceptionV3 import keras

root_dir = os.path.abspath('.') data_dir = os.path.join(root_dir, 'data') os.path.exists(root_dir) os.path.exists(data_dir)

train = pd.read_csv(os.path.join(data_dir, 'images', 'test.csv')) train.head() temp = [] for img_name in train.filename: image_path = os.path.join(data_dir, 'images', img_name) img_tmp = imread(image_path) img = imresize(img_tmp, (299, 299)) img = img.astype('float32') temp.append(img)

train_x = np.stack(temp)

split_size = int(train_x.shape[0]*0.7)

train_x = train_x#, train_x[split_size:] train_y = train.label#,train.label.ix[split_size:] inception_model = InceptionV3(weights=None) inception_model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) trained_model = inception_model.fit(train_x, train_y, validation_data=0.33, nb_epoch=1, batch_size=8) trained_model.save('car_model.h5') print ('Fin de l\'entrainement') ` But I got this error : Exception: Error when checking model target: expected predictions to have shape (None, 1000) but got array with shape (9, 1)

Do you know why ? I think I did all good..

PS : For the shape(9,1), I guess the 9 refers to my 9 classes than I want to learn from

toqitahamid commented 8 years ago

You need to exclude the logistic layer of inception as ImageNet has 1000 class and add your own logistic layer.

Here is a example - https://github.com/fchollet/keras/blob/master/docs/templates/applications.md#fine-tune-inceptionv3-on-a-new-set-of-classes

kushia commented 8 years ago

Hi ! Thanks, this made the job, but I got an other problems, still with inception model.. I open a new issues, we can close this one :-)