Skip to content

Commit

Permalink
Updated file
Browse files Browse the repository at this point in the history
  • Loading branch information
yanukadeneth99 committed May 10, 2023
1 parent f365122 commit 581e389
Showing 1 changed file with 83 additions and 8 deletions.
91 changes: 83 additions & 8 deletions Image_Captioning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,7 @@
"id": "lF4e-SWgmH-R"
},
"source": [
"You can download the features file from [here](#). Make sure to move it into the `export_model` folder. The file must be labelled as `features.pkl`.\n",
"\n",
"**CHANGE THIS**"
"You can download the features file from [here](https://github.com/yanukadeneth99/Image-Captioning-DL/blob/master/Resources/features.pkl). Make sure to move it into the `export_model` folder. The file must be labelled as `features.pkl`."
]
},
{
Expand Down Expand Up @@ -1156,7 +1154,9 @@
"source": [
"### Loading Weights\n",
"\n",
"We can load the weights if they are saved as well. Make sure the file name is `main_model_weights.hdf5` and is under the `export_model` folder."
"We can load the weights if they are saved as well. Make sure the file name is `main_model_weights.hdf5` and is under the `export_model` folder.\n",
"\n",
"You can download the weights from [here](https://github.com/yanukadeneth99/Image-Captioning-DL/blob/master/Resources/main_model_weights.hdf5)."
]
},
{
Expand Down Expand Up @@ -1834,21 +1834,96 @@
},
{
"cell_type": "markdown",
"source": [
"We can see that the guesses the model makes are pretty close and will improve once we train more. \n",
"\n",
"However, moving on, let's setup a way so that you can test with your own image as well.\n",
"\n",
"# Testing\n",
"\n",
"We can upload our custom image to the `test` folder and set the image name in the below variable and run to test."
],
"metadata": {
"id": "YEInN-Pb3r25"
"id": "MYpL53JEGEUO"
}
},
{
"cell_type": "code",
"source": [
"# Create the test folder\n",
"!mkdir test"
],
"metadata": {
"id": "sxtEUZ9iILuT"
},
"source": []
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Set Image to Test\n",
"test_image_path = \"\""
],
"metadata": {
"id": "k05niV1TGQLq"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Load Image\n",
"t_image = load_img(test_image_path, target_size=(224, 224))\n",
"# Covert Image to Numpy Array\n",
"t_image = img_to_array(t_image)\n",
"# Reshape for Model\n",
"t_image = t_image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))\n",
"# Preprocess the values\n",
"t_image = preprocess_input(t_image)\n",
"# Extract features using the model\n",
"t_feature = vgg_model.predict(t_image, verbose=0)\n",
"\n",
"# Predict the caption from the extracted features\n",
"t_caption = predict_caption(model, t_feature, tokenizer, max_length)\n",
"\n",
"# Print the caption\n",
"plt.imshow(image)\n",
"print(f\"Caption Generated : {t_caption}\")"
],
"metadata": {
"id": "7wiAl6GDGayu"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Conclusion\n",
"\n",
"We have created a Neural Network for Image Captioning from Scratch. We can train the model more to perform better and tweak around few values to find the best possible model for this."
],
"metadata": {
"id": "-31QNwVaHMN5"
}
},
{
"cell_type": "markdown",
"metadata": {
"id": "D04bx2U9nVCw"
},
"source": [
"# Credits\n",
"# Links\n",
"\n",
"- [GitHub Project](https://github.com/yanukadeneth99/Image-Captioning-DL)\n",
"- [Twitter](https://twitter.com/yanukadeneth99)\n",
"\n",
"# Resources\n",
"\n",
"- [VGG16 → from scratch using Transfer Learning with Keras and TensorFlow 2](https://narenltk.medium.com/vgg16-from-scratch-using-transfer-learning-with-keras-and-tensorflow-ffee5ae460fb)\n",
"- "
"- [Image Caption Generator using Python | Flickr Dataset | Deep Learning Tutorial](https://www.hackersrealm.net/post/image-caption-generator-using-python)"
]
}
],
Expand Down

0 comments on commit 581e389

Please sign in to comment.