sunshineatnoon/Darknet.keras

Building yolo-tiny on tensorflow

thtrieu opened this issue · 2 comments

Dear @sunshineatnoon your repo is really cool,
after using the crop function in utils, I tried to feed the image into the net I built in tensorflow as follows:

class SimpleNet(object):
    def __init__(self, yolo):

        self.input_x = tf.placeholder(tf.float32, 
            [None, 448, 448, 3], name = "input_x")

        now = self.input_x
        for i in range(yolo.layer_number):
            l = yolo.layers[i]
            if (l.type == "CONVOLUTIONAL"):
                now = tf.nn.conv2d(
                    now,
                    tf.Variable(l.weights.transpose([2,3,1,0])),
                    strides = [1,1,1,1],
                    padding = "SAME")
                now = tf.nn.bias_add(now, tf.Variable(l.biases))
                now = tf.maximum(0.1 * now, now)
            elif l.type == 'MAXPOOL':
                now = tf.nn.max_pool(now,
                    ksize = [1,2,2,1],
                    strides = [1,2,2,1],
                    padding = "SAME")
            elif l.type == 'FLATTEN':
                now = tf.reshape(now, 
                    [-1, int(np.prod(now.get_shape()[1:]))])
                print ('add flat')
            elif l.type == 'CONNECTED':
                now = tf.nn.xw_plus_b(now,
                    tf.Variable(l.weights),
                    tf.Variable(l.biases))
            elif l.type == 'LEAKY':
                now = tf.maximum(0.1 * now, now)
            elif l.type == 'DROPOUT':
                pass
        self.out = now

And then try to feed the image into the net as follows:

                image = crop(img,resize_width=512,resize_height=512,new_width=448,new_height=448)
        image = image.transpose([1,2,0])
        image = np.expand_dims(image, axis = 0)
        feed_dict ={
            model.input_x: image
        }
        timer = Timer()
        timer.tic()
        out = sess.run([model.out], feed_dict)[0]

Can you help me why is it that for the same input image our nets produce different results (out != predictions) and yours seem to be correct one, I have double checked the net construction in tensorflow above and cannot find any mis-correspondence between our nets.

Thank you.

@thtrieu Did you find the answer to your question? I'm trying to study both Darknet.keras and your darkflow. Both are very cool implementations. The SimpleNet you wrote above is very helpful

I have long passed the problem above and do not quite remember what is the answer exactly.