Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need more solved captchas? #144

Open
K1rakishou opened this issue Aug 14, 2022 · 17 comments
Open

Need more solved captchas? #144

K1rakishou opened this issue Aug 14, 2022 · 17 comments

Comments

@K1rakishou
Copy link

K1rakishou commented Aug 14, 2022

Hello. I noticed that you are collecting solved captchas and I'm assuming that's to train a NN model for future use. If I'm correct and you are planning to make it public then I could contribute you solved captchas to make the process faster (the same way you are doing it). I'm currently implementing captcha solver based on https://github.com/AUTOMATIC1111/4chan-captcha-solver model but it's not ideal.

@moffatman
Copy link
Owner

Hi @K1rakishou
I tried using a neural network at the beginning, I made a program to generate fake captchas, but even with a data set of 100,000, I couldn't come up with a working model that would solve those generated captchas. So I gave up on neural networks, I'm not really an expert in that technique. I made the solver using classical techniques, so more data doesn't really help that much, and it is has kind of reached a plateau at ~65% accuracy.

I just rechecked https://github.com/AUTOMATIC1111/4chan-captcha-solver, from a first glance, it seems good and more accurate than my solver. What makes it not ideal? Too big for mobile devices?

By the way, I have ~34,000 captchas at the moment, let me know if it would help you in your effort, and I can provide them.

@K1rakishou
Copy link
Author

K1rakishou commented Aug 14, 2022

Oh I see. Well I'm not an ML expert either, so more captchas won't help me.

This https://github.com/AUTOMATIC1111/4chan-captcha-solver model solves like 80-90% of captchas (I didn't measure it, just a feeling after using it for a couple of weeks) but the slider auto adjustment algorithm sometimes fails as well (which obviously makes the model fail too). You can manually adjust the slider and then solve it again and it works but it requires the user's input.

Too big for mobile devices?

The model itself is like 8 megabytes (tensorflow lite format, you can also enable optimizations when converting it so it will only take 2 megabytes but I don't know how it affects accuracy) however it uses some custom layers (?) and the default tensorflow lite does not support them so I had to include some special dependency with more layer implementations and it's size ended up being like ~40 megabytes just for one cpu architecture. I decided to extract that stuff into a separate apk and I use broadcast receivers to communicate between the main app and the solver app. https://github.com/K1rakishou/4chanCaptchaSolver

@moffatman
Copy link
Owner

moffatman commented Aug 15, 2022

the slider auto adjustment algorithm sometimes fails as well

You should try my slider algorithm here, I have only ever seen one failure in many months of use, and I think it's more efficient than the one in that repo as well.

Future<void> _alignImage() async {

Basically, only compare the pixels of the image on the edge of the background cutouts.

How long does it take to execute the neural model on mobile?

@K1rakishou
Copy link
Author

K1rakishou commented Aug 15, 2022

You should try my slider algorithm here

I will take a look at it but I think it's going to be very hard because the script is doing some additional captcha image transformations (it flips the pixels horizontally, rotates them and then draws everything in the middle of the canvas which also has specifically calculated size + adds some 0xeeeeee colored border around the image).

How long does it take to execute the neural model on mobile?

With no gpu and other kinds of accelerations (only cpu with 4 threads) and on an emulator in debug build it takes ~200ms. The slider auto adjustment however takes like 600-700ms. But all together it's less than a second which is pretty good. Guess it should be slightly better once the apk is built in release mode.

@FrostyFridge
Copy link

Hi, I'm interested in making my own attempt at one of these - Is there any chance I could get access to your captcha datasets @moffatman @K1rakishou ? Thanks!

@moffatman
Copy link
Owner

@FrostyFridge We can talk on discord, add me - Callum#2821

@K1rakishou
Copy link
Author

@moffatman
What's the endpoint for captcha collection? I would like to add support to donate captchas from KurobaEx. Seems like there are people willing to train a model with that data.

@moffatman
Copy link
Owner

@K1rakishou

You can POST images to https://captcha.chance.surf/kuroba.php, use multipart field "text" for the answer, and "image" for the image encoded as PNG.

@K1rakishou
Copy link
Author

Thanks. I will try adding support for it tomorrow.

@K1rakishou
Copy link
Author

K1rakishou commented Aug 5, 2023

For some reason it just keeps returning me status 400, "Missing file" error. I also tried to send it via postman but it gave me an error something like "Failed to move file".

    private suspend fun sendCaptcha(
        captchaBytes: ByteArray,
        captchaSolution: CaptchaSolution.ChallengeWithSolution
    ) {
        Logger.d(TAG, "sendCaptcha() captchaBytes: ${captchaBytes.size}, captchaSolution: ${captchaSolution}")

        val requestBody = MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart(
                name = "text",
                value = captchaSolution.solution.uppercase()
            )
            .addFormDataPart(
                name = "image",
                filename = null,
                body = captchaBytes.toRequestBody(contentType = "image/png".toMediaType())
            )
            .build()

        val request = Request.Builder()
            .url("https://captcha.chance.surf/kuroba.php")
            .post(requestBody)
            .build()

        val response = proxiedOkHttpClient.okHttpClient().suspendCall(request)
        if (!response.isSuccessful) {
            val body = response.body?.string()?.take(256)
            Logger.e(TAG, "sendCaptcha() bad status code: ${response.code}, errorBody: '${body}'")
            return
        }

        Logger.d(TAG, "sendCaptcha() success")
    }

@moffatman
Copy link
Owner

If you try it again, I added more debug output to the response body, we can see what's missing in your request. I think you may need to provide some dummy filename like "image.png" instead of null.

@K1rakishou
Copy link
Author

Ok let me try.

@K1rakishou
Copy link
Author

Here is what I get, it gets cut off at the end.

sendCaptcha() bad status code: 500, errorBody: 'array(1) {
  ["text"]=>
  string(6) "NHRPHW"
}
array(1) {
  ["image"]=>
  array(5) {
    ["name"]=>
    string(9) "image.png"
    ["type"]=>
    string(9) "image/png"
    ["tmp_name"]=>
    string(14) "/tmp/phpeWdHbc"
    ["error"]=>
    int(0)
    ["size"'

@moffatman
Copy link
Owner

One more time, should be ok now

@K1rakishou
Copy link
Author

K1rakishou commented Aug 5, 2023

Sent. Seems good on my end.
Also, please check if the image has correct sizes because I might have fucked it up.

@moffatman
Copy link
Owner

Yep got it

VPDN4G_1691213544

@K1rakishou
Copy link
Author

Nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants