Skip to content

Commit

Permalink
clone module added
Browse files Browse the repository at this point in the history
  • Loading branch information
purveshpatel511 committed Jun 13, 2020
1 parent 351b58f commit 8bc8c1e
Showing 1 changed file with 75 additions and 32 deletions.
107 changes: 75 additions & 32 deletions imageCaptioning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,16 @@
"collapsed_sections": []
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "JDAgp_sTX_st",
"colab_type": "code",
"colab": {}
},
"source": [
Expand All @@ -44,25 +31,79 @@
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "LH2Ikk20YiH_",
"colab_type": "code",
"colab": {}
},
"source": [
"######## Official git repo\n",
"##\n",
"## https://www.github.com/purvesh-linux11/imageCaptioning\n",
"## https://www.github.com/purvesh-linux11/imageCaptioning.git\n",
"##\n",
"##### clone Project from this repo."
"##### clone project moduls\n",
"\n",
"!git clone https://www.github.com/purvesh-linux11/imageCaptioning.git\n",
"!cp -r /content/imageCaptioning/* /content/"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "2AkEa0BupDsF",
"colab_type": "code",
"colab": {}
},
"source": [
"##### copy model from drive and extract here\n",
"\n",
"!cp -r /content/drive/'My Drive'/MODELS/image_captioning_model.zip /content/ \n",
"!unzip image_captioning_model.zip\n",
"!cp -r /content/image_captioning_model/* /content/"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "sYZGzNViwPQ1",
"colab_type": "code",
"colab": {}
},
"source": [
"##### copy photos from drive\n",
"\n",
"!cp -r /content/drive/'My Drive'/photos/* /content/photos/"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "xDwlCAOMRG5q",
"colab_type": "code",
"colab": {}
},
"source": [
"#############################################################\n",
"##\n",
"##\n",
"## Download Model and place it current directory \n",
"## (Link in Readme file)\n",
"##\n",
"##############################################################"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "-ErYFuETaEGX",
"colab_type": "code",
"colab": {}
},
"source": [
Expand Down Expand Up @@ -98,15 +139,15 @@
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "fN-tgbJMbNHt",
"colab_type": "code",
"colab": {}
},
"source": [
"# Choose the trained model --> current is 2\n",
"model_number = \"2\"\n",
"model_path = \"/content/image_captioning_model/model.ckpt-\"+model_number+\"000000\" # Give model path\n",
"vocab_path = \"/content/image_captioning_model/word_counts\"+model_number+\".txt\" # Give word_counts file path\n",
"model_path = \"/content/model.ckpt-\"+model_number+\"000000\" # Give model path\n",
"vocab_path = \"/content/word_counts\"+model_number+\".txt\" # Give word_counts file path\n",
"tf.logging.set_verbosity(tf.logging.INFO)\n",
"\n",
"# Build the inference graph.\n",
Expand All @@ -122,8 +163,8 @@
"#######################################################\n",
"### if tensorflow version is <1.13.2 then you have to check variables name as per tensorflow version\n",
"\n",
"OLD_CHECKPOINT_FILE = \"/content/image_captioning_model/model.ckpt-2000000\" ##Give model path\n",
"NEW_CHECKPOINT_FILE = \"/content/image_captioning_model/model.ckpt-2000000\" ##Give model path\n",
"OLD_CHECKPOINT_FILE = \"/content/model.ckpt-2000000\"\n",
"NEW_CHECKPOINT_FILE = \"/content/model.ckpt-2000000\"\n",
"\n",
"import tensorflow as tf\n",
"vars_to_rename = {\n",
Expand Down Expand Up @@ -163,19 +204,18 @@
{
"cell_type": "code",
"metadata": {
"colab_type": "code",
"id": "DIZLzNZIbgU-",
"colab_type": "code",
"colab": {}
},
"source": [
"image_path = \"./photos/\" #### provide path where image is stored\n",
"filenames = listdir(image_path)\n",
"store = open('./results/logs.txt','w') #### provide path to store captions\n",
"filename = listdir(image_path)\n",
"filenames = [f for f in filename if '.jpg' in f or '.png' in f or '.jpeg' in f]\n",
"store = open('/content/results/logs.txt','w') #### directory to store captions file\n",
"\n",
"for file in filenames:\n",
" try:\n",
" print(image_path+file)\n",
" store.write(image_path+file+\"\\n\")\n",
" img = PIL.Image.open(image_path+file).convert('RGBA')\n",
" box = PIL.Image.new('RGBA', img.size, (255,255,255,0))\n",
" draw = PIL.ImageDraw.Draw(box)\n",
Expand All @@ -185,11 +225,14 @@
" # Ignore begin and end words.\n",
" sentence = [vocab.id_to_word(w) for w in caption.sentence[1:-1]]\n",
" sentence = \" \".join(sentence)\n",
" print(\" %d) %s (p=%f)\" % (i, sentence, math.exp(caption.logprob)))\n",
" store.write(str(i)+\"): \"+sentence+\"\\n\")\n",
" if i==0:\n",
" print(file+\" : %s \" % (sentence))\n",
" #create log file image_name--image_caption\n",
" store.write(file+\" : \"+sentence+\"\\n\")\n",
" except KeyboardInterrupt:\n",
" store.close()\n",
" break"
" break\n",
"store.close()"
],
"execution_count": 0,
"outputs": []
Expand Down

0 comments on commit 8bc8c1e

Please sign in to comment.