Skip to content

Commit

Permalink
Model accuracy - cca 98%
Browse files Browse the repository at this point in the history
  • Loading branch information
JanPalasek committed Apr 19, 2020
1 parent 0a133f4 commit a19af2d
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 37 deletions.
112 changes: 77 additions & 35 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion src/captcha_detection/captcha_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def train(self, inputs, labels, args):
])
label_preprocess_pipeline = LabelPreprocessPipeline(
StringEncoder(available_chars="0123456789")
# OneCharEncoder(available_chars="0123456789")
)

train_x, val_x, train_y, val_y = sklearn.model_selection.train_test_split(
Expand Down Expand Up @@ -186,3 +185,33 @@ def _train_batch(self, inputs, labels):
else:
metric.update_state(y_true=labels, y_pred=logits)
tf.summary.scalar("train/{}".format(name), metric.result())

def predict(self, inputs):
image_preprocess_pipeline = ImagePreprocessorPipeline([
NormalizeImagePreprocessor()
])
inputs = image_preprocess_pipeline(inputs)

return self._predict(inputs).numpy()

@tf.function
def _predict(self, inputs):
y_pred = self._predict_proba(inputs)

if len(y_pred.shape) <= 2:
y_pred = tf.expand_dims(y_pred, axis=1)
y_pred = tf.argmax(y_pred, axis=2)

return y_pred

def predict_proba(self, inputs):
image_preprocess_pipeline = ImagePreprocessorPipeline([
NormalizeImagePreprocessor()
])
inputs = image_preprocess_pipeline(inputs)

return self._predict_proba(inputs).numpy()

@tf.function
def _predict_proba(self, inputs):
return self._model(inputs)
Binary file added src/captcha_detection/model.h5
Binary file not shown.
Loading

0 comments on commit a19af2d

Please sign in to comment.