Code Monkey home page Code Monkey logo

ulozto-captcha-breaker's People

Contributors

janpalasek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ulozto-captcha-breaker's Issues

How to modify this for similar captcha image

Hi, can you explain how to modify this captcha breaker for similar captcha image?
I have captcha like this with 6 digit char and the image color is already gray.

This is the example:
image

Thanks

ImportError: cannot import name 'all_correct_acc' from 'metrics'

Hi,

if i want to tain my own model i keep getting the error message: ImportError: cannot import name 'all_correct_acc' from 'metrics'
can you give me a hint why i get this error message?

i m on windows 10 and Python 3.9.13

EDIT: fixed it with: pip install metrics
getting the code from ulozto-captcha-breaker-master\src\ulozto_captcha_breaker\metric.py
and replaced it in my python folder and there \Lib\site-packages\metrics\metrics.py
looks now like this:


import tensorflow as tf


def all_correct_acc(y_true: tf.Tensor, y_pred: tf.Tensor):
    """
    Computes accuracy between y_true and y_pred in the following manner:

    - If i-th sample has all values on y_pred same as on y_true, then 1.
    - Otherwise 0.

    It is hence more restricting then a typical accuracy.

    Args:
        y_true (tf.Tensor): 2D tensor of shape (N, L), where N is the number of samples and L is length of the vector (number of characters).
        y_pred: 2D tensor of shape (N, L), where N is the number of samples and L is length of the vector (number of characters)

    Returns:
        Accuracy: number between [0, 1] denoting how many codes were predicted correctly.
    """
    if y_true.shape[0] is None and y_true.shape[1] is None and y_true.shape[2] is None:
        return tf.convert_to_tensor(0)

    # cast to int64 so we can compare it
    y_true = tf.cast(y_true, tf.dtypes.int64)

    if len(y_pred.shape) <= 2:
        y_pred = tf.expand_dims(y_pred, axis=1)
    if len(y_true.shape) <= 1:
        y_true = tf.expand_dims(y_true, axis=1)
    y_pred = tf.argmax(y_pred, axis=2)
    correct = y_true == y_pred
    # tf.print(f"Pred shape: {y_true.shape}", output_stream=sys.stdout)

    all_correct = tf.reduce_all(correct, axis=1)
    all_correct = tf.cast(all_correct, tf.dtypes.float32)

    return tf.reduce_mean(all_correct)

now i got a new error message when i want to train my own model:
image

the code in image_preprocessors.py:

import numpy as np
from PIL import Image


class ConvertToGrayscalePreprocessor:
    """
    Converts image to grayscale.
    """
    def __call__(self, img: np.ndarray):
        r, g, b = img[:, :, 0], img[:, :, 1], img[:, :, 2]
        output = 0.299 * r + 0.587 * g + 0.114 * b
        return output


class ImageCutPreprocessor:
    def __init__(self, pieces_count: int):
        self._pieces_count = pieces_count

    def __call__(self, image: np.ndarray):
        images = np.split(image, self._pieces_count, axis=1)

        return np.array(images)


class NormalizeImagePreprocessor:
    """
    Converts image from byte format (values are integers in {0, ..., 255} to normalized float format (values are
    floats in the interval [0, 1].
    """
    def __init__(self):
        pass

    def __call__(self, image):
        image = image.astype(np.float32) / 255
        image = np.expand_dims(image, axis=len(image.shape))
        return image


class ResizePreprocessor:
    """
    Resizes image to target width and height.
    """
    def __init__(self, target_height, target_width):
        self._target_height = target_height
        self._target_width = target_width

    def __call__(self, img: np.ndarray):
        return img.resize(img, (self._target_width, self._target_height))

Something bad when creating .tflite file

Hi,
I spend whole weekend trying to train simple 0-9 captcha solver, but I think I got stuck on the last step. I already passed test with high success, but final .tflite model does not work properly. Can you please help a little?
Steps to reproduce:

git clone [email protected]:JanPalasek/ulozto-captcha-breaker.git
cd ulozto-captcha-breaker
python -m venv "venv"
source venv/bin/activate
python -m pip install --upgrade pip
python -m pip install --upgrade wheel setuptools pip-tools
python -m piptools sync
python -m pip install -e .

python bin/simple_captcha_generate.py --height=70 --width=175 --available_chars="0123456789" --captcha_length=4 --dataset_size=10000
python bin/captcha_annotate.py --val_split=0.1 --test_split=0.1

python bin/train.py --available_chars="0123456789" --captcha_length=4

In this moment, I stopped script after a while, 7th epoch had val_all_correct_acc: 0.9453, so for testing purposes enough.

Then I ran test.py:

python bin/test.py --available_chars="0123456789" --captcha_length=4 --weights_file=/home/manas/Projects/2.Other/ulozto-captcha-breaker/out/logs/train.py-2023-09-10_163320-ac=0123456789,bs=32,cl=4,e=1500,fl=0,l=1e-05,od=out,pm=None,rl=False,smp=None,s=42,tih=None,tiw=None,wf=None/cp-07.h5

with result :

32/32 [==============================] - 2s 40ms/step
Test acc: 0.92

And .csv file with results, 92% succesfully as written. After that I have model folder in out directory. I did:

python bin/create_tflite.py --pretrained_model=out/model

with output to terminal (I dont know if it is useful):

2023-09-11 18:07:01.736468: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:362] Ignored output_format.
2023-09-11 18:07:01.736497: W tensorflow/compiler/mlir/lite/python/tf_tfl_flatbuffer_helpers.cc:365] Ignored drop_control_dependency.
2023-09-11 18:07:01.737129: I tensorflow/cc/saved_model/reader.cc:45] Reading SavedModel from: out/model
2023-09-11 18:07:01.753180: I tensorflow/cc/saved_model/reader.cc:89] Reading meta graph with tags { serve }
2023-09-11 18:07:01.753227: I tensorflow/cc/saved_model/reader.cc:130] Reading SavedModel debug info (if present) from: out/model
2023-09-11 18:07:01.785731: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:354] MLIR V1 optimization pass is not enabled
2023-09-11 18:07:01.796363: I tensorflow/cc/saved_model/loader.cc:229] Restoring SavedModel bundle.
2023-09-11 18:07:01.967260: I tensorflow/cc/saved_model/loader.cc:213] Running initialization op on SavedModel bundle at path: out/model
2023-09-11 18:07:02.019981: I tensorflow/cc/saved_model/loader.cc:305] SavedModel load for tags { serve }; Status: success: OK. Took 282855 microseconds.
2023-09-11 18:07:02.140917: I tensorflow/compiler/mlir/tensorflow/utils/dump_mlir_util.cc:268] disabling MLIR crash reproducer, set env var `MLIR_CRASH_REPRODUCER_DIRECTORY` to enable.

After this, model.tflite was created in out directory. I copied randomly a few images from data directory to base directory, renamed them test1.jpg - test5.jpg (which are: 0336, 3185, 7881, 8388, 9977) and then tried that .tflite model:

python bin/predict.py --model_path=out/model.tflite --available_chars="0123456789" --image_path=test1.png
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Decoded label is the following:
1117

python bin/predict.py --model_path=out/model.tflite --available_chars="0123456789" --image_path=test2.png
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Decoded label is the following:
1197

python bin/predict.py --model_path=out/model.tflite --available_chars="0123456789" --image_path=test3.png
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Decoded label is the following:
1147

python bin/predict.py --model_path=out/model.tflite --available_chars="0123456789" --image_path=test4.png
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Decoded label is the following:
1147

python bin/predict.py --model_path=out/model.tflite --available_chars="0123456789" --image_path=test5.png
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Decoded label is the following:
1147

So this seems I do something wrong when I try to create .tflite file, can you please little help?

Reading problems Vzum

Hello, Im trying to download some apps with the program i use and the program uses this script, There are some problems its not as good as before now it gets very easily broken and it can't read that good, please fix that.

I can't try the model After three days of training

python -m pip install -r "requirements.txt" -e .
python bin/simple_captcha_generate.py --height=80 --width=320 --available_chars="012345678" --captcha_length=4 --dataset_size=100
python bin/captcha_annotate.py --val_split=0.1 --test_split=0.1 --case_sensitive
python bin/train.py --available_chars="012345678" --captcha_length=4

after running all these step there is 1500 h5 files was generated , so now how to test it ? and there to find the acutal model?

How to use predict.py

Hello,

I've generate my own training model.

But Get error when try to run with predict.py.

python bin/predict.py --available_chars=abcdefghijklmnopqrstuvwxyz1234567890 --image_path='out/data/22c7g7_b081c975-f657-4e32-872a-d879717ca983.png' --model_path=out/model.tflite

Traceback (most recent call last): File "/Users/daffigusti/development/mutasibank_bot/ulozto-captcha-breaker/bin/predict.py", line 37, in <module> main(args) File "/Users/daffigusti/development/mutasibank_bot/ulozto-captcha-breaker/bin/predict.py", line 20, in main model : tf_keras.Model = tf_keras.models.load_model(args.model_path) File "/Users/daffigusti/development/mutasibank_bot/ulozto-captcha-breaker/venv/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None File "/Users/daffigusti/development/mutasibank_bot/ulozto-captcha-breaker/venv/lib/python3.9/site-packages/h5py/_hl/files.py", line 533, in __init__ fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr) File "/Users/daffigusti/development/mutasibank_bot/ulozto-captcha-breaker/venv/lib/python3.9/site-packages/h5py/_hl/files.py", line 226, in make_fid fid = h5f.open(name, flags, fapl=fapl) File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "h5py/h5f.pyx", line 106, in h5py.h5f.open OSError: Unable to open file (file signature not found)

Plz help with this error.

Thanks.

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.