michalmarsalek / pecaptcha Goto Github PK
View Code? Open in Web Editor NEWProject Euler captcha solver
Project Euler captcha solver
Hello, I'm trying out your project which I found interesting in a virtual env, with tensorflow 2.7.0 , and I can't make it work, could you help me?
This is the output of running test_from_disk.py:
WARNING:tensorflow:Layers in a Sequential model should only have a single input tensor, but we receive a <class 'tuple'> input: (<tf.Tensor 'IteratorGetNext:0' shape=(None, 24, 1) dtype=uint8>, <tf.Tensor 'IteratorGetNext:1' shape=(None, 24, 1) dtype=uint8>, <tf.Tensor 'IteratorGetNext:2' shape=(None, 24, 1) dtype=uint8>, <tf.Tensor 'IteratorGetNext:3' shape=(None, 24, 1) dtype=uint8>, <tf.Tensor 'IteratorGetNext:4' shape=(None, 24, 1) dtype=uint8>)
Consider rewriting this model with the Functional API.
WARNING:tensorflow:Model was constructed with shape (None, 24, 24, 1) for input KerasTensor(type_spec=TensorSpec(shape=(None, 24, 24, 1), dtype=tf.float32, name='rescaling_input'), name='rescaling_input', description="created by layer 'rescaling_input'"), but it was called on an input with incompatible shape (None, 24, 1, 1).
Traceback (most recent call last):
File "test_from_disk.py", line 3, in <module>
print("Success rate", pe_captcha.test_from_disk())
File "/home/boxxo/Desktop/environments/PEcaptcha/pe_captcha/__init__.py", line 216, in test_from_disk
return correct/total
ZeroDivisionError: division by zero
Keras in the warning encourages to use functional models for multi-input layers, but there is nothing wrong with doing so, so I we can ignore that, but there's a problem I think in the function solve.
It returns a tuple and you store it into pred, but total counter doesn't go up, making it a division by 0.
I made a test.py which contains justs a few lines:
im = cv2.imread('test_online.png')
model = pe_captcha.load_model("model0")
pred, _, _ = pe_captcha.solve(model, im)
print(pred)
and it returns:
Traceback (most recent call last):
File "test.py", line 13, in <module>
pred, _, _ = pe_captcha.solve(model, im)
File "/home/boxxo/Desktop/environments/PEcaptcha/pe_captcha/__init__.py", line 179, in solve
prediction_vectors = model.predict(chars)
File "/home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/keras/engine/data_adapter.py", line 245, in __init__
num_samples = set(int(i.shape[0]) for i in tf.nest.flatten(inputs)).pop()
KeyError: 'pop from an empty set'
meanwhile by executing the standard collect_training.py it yelds:
WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), *NOT* tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
2021-11-30 16:30:10.374403: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/cv2/../../lib64:
2021-11-30 16:30:10.374475: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2021-11-30 16:30:10.374512: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (boxxo-vb): /proc/driver/nvidia/version does not exist
2021-11-30 16:30:10.374909: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Layers in a Sequential model should only have a single input tensor, but we receive a <class 'tuple'> input: (<tf.Tensor 'IteratorGetNext:0' shape=(None, 24, 1) dtype=uint8>, <tf.Tensor 'IteratorGetNext:1' shape=(None, 24, 1) dtype=uint8>, <tf.Tensor 'IteratorGetNext:2' shape=(None, 24, 1) dtype=uint8>, <tf.Tensor 'IteratorGetNext:3' shape=(None, 24, 1) dtype=uint8>, <tf.Tensor 'IteratorGetNext:4' shape=(None, 24, 1) dtype=uint8>)
Consider rewriting this model with the Functional API.
WARNING:tensorflow:Model was constructed with shape (None, 24, 24, 1) for input KerasTensor(type_spec=TensorSpec(shape=(None, 24, 24, 1), dtype=tf.float32, name='rescaling_input'), name='rescaling_input', description="created by layer 'rescaling_input'"), but it was called on an input with incompatible shape (None, 24, 1, 1).
Traceback (most recent call last):
File "collect_training.py", line 3, in <module>
pe_captcha.collect_training("model_t", "model0")
File "/home/boxxo/Desktop/environments/PEcaptcha/pe_captcha/__init__.py", line 64, in collect_training
pred, _, _ = solve(old_model, img) if old_model else None
File "/home/boxxo/Desktop/environments/PEcaptcha/pe_captcha/__init__.py", line 179, in solve
prediction_vectors = model.predict(chars)
File "/home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py", line 1129, in autograph_handler
raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:
File "/home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/keras/engine/training.py", line 1621, in predict_function *
return step_function(self, iterator)
File "/home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/keras/engine/training.py", line 1611, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/keras/engine/training.py", line 1604, in run_step **
outputs = model.predict_step(data)
File "/home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/keras/engine/training.py", line 1572, in predict_step
return self(x, training=False)
File "/home/boxxo/Desktop/environments/PEcaptcha/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
ValueError: Exception encountered when calling layer "max_pooling2d" (type MaxPooling2D).
Negative dimension size caused by subtracting 2 from 1 for '{{node sequential/max_pooling2d/MaxPool}} = MaxPool[T=DT_FLOAT, data_format="NHWC", explicit_paddings=[], ksize=[1, 2, 2, 1], padding="VALID", strides=[1, 2, 2, 1]](sequential/conv2d/Relu)' with input shapes: [?,24,1,32].
Call arguments received:
• inputs=tf.Tensor(shape=(None, 24, 1, 32), dtype=float32)
Could you help me?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.