Created using Colaboratory

This commit is contained in:
George Mihaila
2018-05-28 16:24:37 -05:00
parent 0b373f7bcf
commit 19f4c09777

View File

@@ -247,6 +247,46 @@
"name": "stdout"
}
]
},
{
"metadata": {
"id": "A-KDhE9Forgg",
"colab_type": "code",
"colab": {}
},
"cell_type": "code",
"source": [
"# prediciton generator some code\n",
"\n",
"def TestGenerator(path_data, max_queue_size, n_articles):\n",
" x = [] # input batch examples\n",
" \n",
" index = 1\n",
" epoch = 0\n",
"\n",
" with (open('%s.pickle'%path_data, \"rb\")) as openfile:\n",
" while True:\n",
" try:\n",
" ID, content, title, media, source, published = pickle.load(openfile)\n",
" x.append(content)\n",
"\n",
" if ((index)%max_queue_size == 0) or ((n_articles - index) < max_queue_size):\n",
" x = np.array(x)\n",
" # output data\n",
" yield x\n",
" x = []\n",
"\n",
" index += 1\n",
" except EOFError:\n",
" break\n",
" \n",
"test_gen = TestGenerator(path_data='test', max_queue_size=2, n_articles=n_test) \n",
"\n",
"predict = model.predict_generator(generator=test_gen, steps=5, max_queue_size=10, workers=1)\n",
"print predict[0]"
],
"execution_count": 0,
"outputs": []
}
]
}