Exemplo n.º 1
0
def get_kaggle_reader(validation_pct=.2):
    train_file = Path('./train.zip')
    test_file = Path('./test.zip')
    if not train_file.is_file() or not test_file.is_file():
        print('👇👇👇👇👇👇👇👇👇👇👇👇👇')
        print(
            'Please put train.zip and test.zip from '
            'https://www.kaggle.com/c/dogs-vs-cats-redux-kernels-edition to project root path.'
        )
        raise FileNotFoundError()

    train_arc = ZipTarReader.auto(train_file.name)
    test_arc = ZipTarReader.auto(test_file.name)

    file_list = train_arc.shuffled_namelist()
    file_list = np.array(file_list)
    mid = int(len(file_list) * validation_pct)
    train_file_list = file_list[mid:]
    vali_file_list = file_list[:mid]

    return BatchReader.BatchReader(train_arc, train_file_list, KaggleLabelClassifier),\
        BatchReader.BatchReader(train_arc, vali_file_list, KaggleLabelClassifier),\
        BatchReader.BatchReader(test_arc, test_arc.namelist(), KaggleLabelClassifier)
Exemplo n.º 2
0
def get_reader(filename):
    arc = ZipTarReader.auto(filename)
    return BatchReader.BatchReader(arc, arc.namelist(), KaggleLabelClassifier)
Exemplo n.º 3
0
import BatchReader as dataset

import tensorflow as tf
import numpy as np

max_it =int(1e4 + 1)
IMAGE_HEIGHT = 64
IMAGE_WIDTH = 256
MAX_CAPTCHA = 5
CHAR_SET_LEN = 10
batch_size = 64
file = open('acc.txt','a')

train_dataset_reader = dataset.BatchReader(index_file='index')
X = tf.placeholder(tf.float32, [None, IMAGE_HEIGHT*IMAGE_WIDTH])
Y = tf.placeholder(tf.float32, [None, MAX_CAPTCHA*CHAR_SET_LEN])
keep_prob = tf.placeholder(tf.float32) # dropout

# CNN
def crack_captcha_cnn(w_alpha=0.01, b_alpha=0.1):
	x = tf.reshape(X, shape=[-1, IMAGE_HEIGHT, IMAGE_WIDTH, 1])
	# 4 conv layer
	w_c1 = tf.Variable(w_alpha*tf.random_normal([3, 3, 1, 32]))
	b_c1 = tf.Variable(b_alpha*tf.random_normal([32]))
	conv1 = tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(x, w_c1, strides=[1, 1, 1, 1], padding='SAME'), b_c1))
	conv1 = tf.nn.max_pool(conv1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
	conv1 = tf.nn.dropout(conv1, keep_prob)

	w_c2 = tf.Variable(w_alpha*tf.random_normal([3, 3, 32, 64]))
	b_c2 = tf.Variable(b_alpha*tf.random_normal([64]))
	conv2 = tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(conv1, w_c2, strides=[1, 1, 1, 1], padding='SAME'), b_c2))
Exemplo n.º 4
0
import BatchReader as dataset
import os
import time
from CaptchaModel import Captcha

# load model
model = Captcha()
model.load_checkpoint('crack_capcha0.994400002956.model-9960')

# load dataset
dataset = dataset.BatchReader(ratio=0.01, test_size=1000)
images, labels = dataset.get_val_batch(0, 1000)

count = len(labels)
correct = 0

# start timing
start = time.time()
t = start

# start testing
for i in range(count):
    image = images[i]
    label = labels[i]
    pred = model.predict(image)
    text = ''.join(map(str, pred))
    if text == label:
        correct += 1
    else:
        print(label, text)
        pass