diff --git a/src/HowBadIsMyBatch.ipynb b/src/HowBadIsMyBatch.ipynb index 7fcf4468aed..2f8d0669c40 100644 --- a/src/HowBadIsMyBatch.ipynb +++ b/src/HowBadIsMyBatch.ipynb @@ -254,7 +254,6 @@ " vocabulary=char_to_num.get_vocabulary(),\n", " mask_token=None, invert=True)\n", "\n", - "\n", "def encode_single_sample(img_path):\n", " # 1. Read image\n", " img = tf.io.read_file(img_path)\n", @@ -268,11 +267,13 @@ " # dimension to correspond to the width of the image.\n", " img = tf.transpose(img, perm=[1, 0, 2])\n", " # 7. Return a dict as our model is expecting two inputs\n", + " return asSingleSampleBatch(img)\n", + "\n", + "def asSingleSampleBatch(img):\n", " array = keras.utils.img_to_array(img)\n", " array = np.expand_dims(array, axis=0)\n", " return array\n", "\n", - "\n", "def decode_batch_predictions(pred):\n", " input_len = np.ones(pred.shape[0]) * pred.shape[1]\n", " # Use greedy search. For complex tasks, you can use beam search\n", @@ -284,7 +285,6 @@ " output_text.append(res)\n", " return output_text\n", "\n", - "\n", "def load_model():\n", " _model = keras.models.load_model('model')\n", " model = keras.models.Model(\n", @@ -292,13 +292,11 @@ " _model.get_layer(name=\"dense2\").output)\n", " return model\n", "\n", - "\n", "def getTextInCaptchaImage(captchaImageFile):\n", " batchImages = encode_single_sample(captchaImageFile)\n", " preds = model.predict(batchImages)\n", " return decode_batch_predictions(preds)[0]\n", "\n", - "\n", "print(\"loading model...\")\n", "model = load_model()\n", "model.summary()"