coomdev
9 months ago
5 changed files with 915 additions and 867 deletions
@ -1,3 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:38fe538eaa6f78c6d64cfa7af477d6f6680265c3faa97386f921131e436e215a |
|||
size 47170376 |
|||
oid sha256:61e6c4d5689ecaf2056fa81f7e02163371dbdace2dba0527069fe21cb5bf98c5 |
|||
size 791405 |
|||
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,47 @@ |
|||
import os |
|||
import numpy as np |
|||
import matplotlib.pyplot as plt |
|||
import sys |
|||
|
|||
from pathlib import Path |
|||
from collections import Counter |
|||
|
|||
import tensorflow as tf |
|||
from tensorflow import keras |
|||
from tensorflow.keras import layers |
|||
|
|||
class CTCLayer(layers.Layer): |
|||
def __init__(self, name=None): |
|||
super().__init__(name=name) |
|||
self.loss_fn = keras.backend.ctc_batch_cost |
|||
|
|||
def call(self, y_true, y_pred): |
|||
# Compute the training-time loss value and add it |
|||
# to the layer using `self.add_loss()`. |
|||
batch_len = tf.cast(tf.shape(y_true)[0], dtype="int64") |
|||
input_length = tf.cast(tf.shape(y_pred)[1], dtype="int64") |
|||
label_length = tf.cast(tf.shape(y_true)[1], dtype="int64") |
|||
|
|||
input_length = input_length * tf.ones(shape=(batch_len, 1), dtype="int64") |
|||
label_length = label_length * tf.ones(shape=(batch_len, 1), dtype="int64") |
|||
|
|||
loss = self.loss_fn(y_true, y_pred, input_length, label_length) |
|||
self.add_loss(loss) |
|||
|
|||
# At test time, just return the computed predictions |
|||
return y_pred |
|||
|
|||
|
|||
print("loading"); |
|||
model = tf.keras.saving.load_model("captcha_75_25.tf", custom_objects={'CTCLayer': CTCLayer}); |
|||
|
|||
print("extracting"); |
|||
pmodel = keras.models.Model( |
|||
model.get_layer(name="image").input, model.get_layer(name="dense2").output |
|||
) |
|||
print("saving"); |
|||
|
|||
tf.keras.saving.save_model(pmodel, "pcaptcha_75_25.keras") |
|||
tf.keras.saving.save_model(pmodel, "pcaptcha_75_25.h5") |
|||
|
|||
print("done"); |
@ -1,3 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:b3d1959699ed9381dc680dcb6676e90670c6841c2b97fcf696ff6c2db261e1f5 |
|||
size 15704896 |
|||
oid sha256:f673767adc061648864cf142f2854df49c04ba0f717da152130cb007627e150d |
|||
size 1863520 |
|||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue