Git Product home page Git Product logo

Comments (2)

sloanyyc avatar sloanyyc commented on May 29, 2024

同求,需要吧 tf.constant(input_images) 改成 tf.var... 但是不会呀

from captcha_recognize.

sloanyyc avatar sloanyyc commented on May 29, 2024

已经处理好了,
captcha_model.py 中增加方法

def test(images, keep_prob):
images = tf.reshape(images, [-1, IMAGE_HEIGHT, IMAGE_WIDTH, 1])

with tf.variable_scope('conv1') as scope:
    kernel = _weight_variable('weights', shape=[3, 3, 1, 64])
    biases = _bias_variable('biases', [64])
    pre_activation = tf.nn.bias_add(_conv2d(images, kernel), biases)
    conv1 = tf.nn.relu(pre_activation, name=scope.name)

pool1 = _max_pool_2x2(conv1, name='pool1')

with tf.variable_scope('conv2') as scope:
    kernel = _weight_variable('weights', shape=[3, 3, 64, 64])
    biases = _bias_variable('biases', [64])
    pre_activation = tf.nn.bias_add(_conv2d(pool1, kernel), biases)
    conv2 = tf.nn.relu(pre_activation, name=scope.name)

pool2 = _max_pool_2x2(conv2, name='pool2')

with tf.variable_scope('conv3') as scope:
    kernel = _weight_variable('weights', shape=[3, 3, 64, 64])
    biases = _bias_variable('biases', [64])
    pre_activation = tf.nn.bias_add(_conv2d(pool2, kernel), biases)
    conv3 = tf.nn.relu(pre_activation, name=scope.name)

pool3 = _max_pool_2x2(conv3, name='pool3')

with tf.variable_scope('conv4') as scope:
    kernel = _weight_variable('weights', shape=[3, 3, 64, 64])
    biases = _bias_variable('biases', [64])
    pre_activation = tf.nn.bias_add(_conv2d(pool3, kernel), biases)
    conv4 = tf.nn.relu(pre_activation, name=scope.name)

pool4 = _max_pool_2x2(conv4, name='pool4')

with tf.variable_scope('local1') as scope:
    batch_size = 1  # images.get_shape()[0].value
    reshape = tf.reshape(pool4, [batch_size, -1])
    # dim = reshape.get_shape()[1].value
    # dim = 512  # for 26x60
    dim = 2048 # for 52x120
    # dim = 3200 # for 70x160
    weights = _weight_variable('weights', shape=[dim, 1024])
    biases = _bias_variable('biases', [1024])
    local1 = tf.nn.relu(tf.matmul(reshape, weights) + biases, name=scope.name)

local1_drop = tf.nn.dropout(local1, keep_prob)

with tf.variable_scope('softmax_linear') as scope:
    weights = _weight_variable('weights', shape=[1024, CHARS_NUM * CLASSES_NUM])
    biases = _bias_variable('biases', [CHARS_NUM * CLASSES_NUM])
    softmax_linear = tf.add(tf.matmul(local1_drop, weights), biases, name=scope.name)

return tf.reshape(softmax_linear, [-1, CHARS_NUM, CLASSES_NUM])

调用模型

def input_image(image_path, image_height, image_width):
image = Image.open(image_path)
image_gray = image.convert('L')
image_resize = image_gray.resize(size=(image_width, image_height))
image.close()
input_img = np.array(image_resize, dtype='float32')
input_img = np.multiply(input_img.flatten(), 1. / 255) - 0.5
return np.reshape(input_img, (image_height, image_width, 1))

tf.placeholder(tf.float32, [None, image_height, image_width, 1]) # 特征向量
logits = captcha.test(self.X, keep_prob=1)
...
image = input_image(img, self.image_height, self.image_width)
...
predict_result = sess.run(self.predict, feed_dict={self.X: [image]})

from captcha_recognize.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.