tflearn / tflearn

Deep learning library featuring a higher-level API for TensorFlow.
http://tflearn.org
Other
9.62k stars 2.41k forks source link

ox 17 Alexnet on my own dataset, acc remains very low 14~19% #312

Open iAceLee opened 8 years ago

iAceLee commented 8 years ago

Hello Aymeric, I am sorry to bother U again. Last few days I've asked U a question about multi-GPUs support and the low training accuracy, U said to me that maybe it's because my dataset's problem. However my teacher trained this dataset on Caffe and it converges very well......

Here is the specific describe of my problem:

My dataset consists of 7 kinds of cloth pictures(about 400*400 pixels), each kind contains about 4800 training pics and 1000 validations. I use the TFLearn's example---alexnet for ox17---as my network architectures, and changed some parameters based on it. My code is showed below:

from __future__ import division, print_function, absolute_import

import tflearn
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.normalization import local_response_normalization
from tflearn.layers.estimator import regression
from tflearn.data_utils import image_preloader

#import tflearn.datasets.oxflower17 as oxflower17                               #original ox17 code
#X, Y = oxflower17.load_data(one_hot=True, resize_pics=(227, 227))

train_dataset_file = 'train_list.txt' 
val_dataset_file = 'val_list.txt'

X, Y = image_preloader(train_dataset_file, image_shape=(227, 227),       #use the 'image_preloader'                    
                       mode='file', categorical_labels=True,
                       normalize=True)
X_val, Y_val = image_preloader(val_dataset_file, image_shape=(227, 227),
                       mode='file', categorical_labels=True,
                       normalize=True)
# Building 'AlexNet'
network = input_data(shape=[None, 227, 227, 3])
network = conv_2d(network, 96, 11, strides=4, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = conv_2d(network, 256, 5, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = conv_2d(network, 384, 3, activation='relu')
network = conv_2d(network, 384, 3, activation='relu')
network = conv_2d(network, 256, 3, activation='relu')
network = max_pool_2d(network, 3, strides=2)
network = local_response_normalization(network)
network = fully_connected(network, 4096, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, 4096, activation='tanh')
network = dropout(network, 0.5)
network = fully_connected(network, 7, activation='softmax')             #change the output from 17 to 7
network = regression(network, optimizer='momentum',
                     loss='categorical_crossentropy',
                     learning_rate=0.001)
# Training
model = tflearn.DNN(network, checkpoint_path='model_alexnet',
                    max_checkpoints=1, tensorboard_verbose=2)
model.fit(X, Y, n_epoch=1000, shuffle=True, validation_set=(X_val, Y_val), 
          show_metric=True, batch_size=128, snapshot_step=200,
          snapshot_epoch=False, run_id='alexnet_pattern')

All I did is changed the way image read and the number of output kinds. I have also changed the batchsize to different value(64, 128 etc.), but it didn't work. The accuracy remains in 14% to 19% all the time.

Is there any obvious mistake I've made? About a week spent on it. It's going to drive me crazy T^T

Thank u all.

p.s. there is not any error occured when I am running it. everything seems OK except for the incredable low accuracy.

aymericdamien commented 8 years ago

Maybe you can try to do finetuning (load vgg16 weights) and retrain for your own task. See: https://github.com/tflearn/models. You may get better performances.

aymericdamien commented 8 years ago

Also for your network, could you try to use Adam instead of Momentum?

network = regression(network, optimizer='adam', loss='categorical_crossentropy', learning_rate=0.001)
kengz commented 8 years ago

@iAceLee here's some notes one why it's advisable sometimes to NOT train such CNN from scratch, and thus the need for fine-tuning. Might be useful! http://cs231n.github.io/transfer-learning/