tensorlayer / TensorLayer

Deep Learning and Reinforcement Learning Library for Scientists and Engineers
http://tensorlayerx.com
Other
7.33k stars 1.61k forks source link

How to use "fit" function when I use CNN, x&y is placeholder #215

Closed VisanXJ closed 7 years ago

VisanXJ commented 7 years ago

sorry, I have a question about how can i use fit function when I use CNN. I loaded minist dataset as you did, but I don't know how to apply it. `X_train, y_train, X_val, y_val, X_test, y_test = load_dataset(dataset_dir = dataset_path, shape=(-1, 32, 32, 1)) sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) ... x_train_batch, y_train_batch = tf.train.shuffle_batch([X_train, y_train], batch_size=batch_size, capacity=2000, min_after_dequeue=1000, num_threads=2) x_test_batch, y_test_batch = tf.train.batch([X_test, y_test], batch_size=batch_size, capacity=50000, num_threads=2) ... x_crop = tf.placeholder(tf.float32, shape=[batchsize, 32, 32, 1], name='x') y_ = tf.placeholder(tf.int32, shape=[batchsize,], name='y') network, cost, acc = model(xcrop, y, None) ...

train the network

tl.utils.fit(sess, network, train_op, cost, X_train, y_train, x_crop, y_,
            acc=acc, batch_size=1, n_epoch=50, print_freq=5,
            X_val=X_test, y_val=y_test, eval_train=False, tensorboard=True)

... `

I notice the debug otput is "Cannot feed value of shape (1, 32, 32, 1) for Tensor 'x_:0', which has shape '(13, 32, 32, 1)'" and batch_size=13

Any problem here? Thank you for your help

zsdonghao commented 7 years ago

the exception already told you the reason Cannot feed value of shape (1, 32, 32, 1) for Tensor 'x_:0', which has shape '(13, 32, 32, 1) you should set batch_size=13 in fit

VisanXJ commented 7 years ago

sorry! but the lastest debug ouputs says "Start training the network ..." but no any other info

zsdonghao commented 7 years ago

this may helps https://github.com/zsdonghao/tensorlayer/blob/master/example/tutorial_mnist_simple.py