Skip to content

Instantly share code, notes, and snippets.

@yunho0130
Created November 9, 2018 04:15
Show Gist options
  • Save yunho0130/6440ac9e8dff9d42938863230d1585d6 to your computer and use it in GitHub Desktop.
Save yunho0130/6440ac9e8dff9d42938863230d1585d6 to your computer and use it in GitHub Desktop.
Adding Multiprocessing
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Hyperparameter Tuning"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Hyperparameter Tuning form Deep Learning by Andrew Ng \n",
"[66](https://www.youtube.com/watch?v=WrICwRrvuIc&list=PLBAGcD3siRDguyYYzhVwZ3tLvOyyG5k6K&index=66)\n",
"[67](https://www.youtube.com/watch?v=VUbrW8OK3uo&index=67&list=PLBAGcD3siRDguyYYzhVwZ3tLvOyyG5k6K)\n",
"[68](https://www.youtube.com/watch?v=wP-DzAtE71g&index=68&list=PLBAGcD3siRDguyYYzhVwZ3tLvOyyG5k6K)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" from ._conv import register_converters as _register_converters\n"
]
}
],
"source": [
"import numpy as np\n",
"import tensorflow as tf\n",
"import matplotlib.pyplot as plt\n",
"import time\n",
"\n",
"from data_loading import load_fashion_mnist\n",
"from model_CNN import CNN_fashion_mnist_hyperparameter_search\n",
"\n",
"%matplotlib inline\n",
"\n",
"def hyperparameter_training(name):\n",
" print (name, \" is runing\")\n",
"\n",
" \" Data Loading \"\n",
" data = load_fashion_mnist()\n",
" x_train, x_test, y_train, y_test, y_train_cls, y_test_cls, class_names = data\n",
"\n",
"\n",
" \" Hyperparameter Tuning \"\n",
" lr_list = []\n",
" fc_list = []\n",
" test_accuracy_list = []\n",
"\n",
" lr_op = 0.02\n",
" fc_op = 900\n",
" global_max_test_accuracy = 0.1\n",
"\n",
" for k in range(10):\n",
" lr_list_temp = lr_op * 10 ** np.random.uniform(-2.0/((k+1)**2), 2.0/((k+1)**2), 10)\n",
" fc_list_temp = fc_op + np.random.randint(-(10-k)*50, (10-k)*50, 10)\n",
"\n",
" for i in range(10):\n",
" tf.reset_default_graph()\n",
" g = tf.Graph() \n",
" with g.as_default():\n",
" with tf.Session(graph=g) as sess:\n",
" with tf.variable_scope(\"cnn_fashion_mnist_{}\".format(str(10*k+i))):\n",
" classifier = CNN_fashion_mnist_hyperparameter_search(sess, \n",
" learning_rate=lr_list_temp[i],\n",
" fc_size=fc_list_temp[i])\n",
" classifier.data_loading(data)\n",
" classifier.graph_construction()\n",
" tf.global_variables_initializer().run(session=sess)\n",
" classifier.train(is_print=True)\n",
" classifier.save(sess=sess, save_path='graphs/cnn_fashion_mnist_{}'.format(str(10*k+i)), is_print=True)\n",
" test_accuracy = classifier.print_test_accuracy(is_print=True)\n",
"\n",
" lr_list.append(lr_list_temp[i])\n",
" fc_list.append(fc_list_temp[i])\n",
" test_accuracy_list.append(test_accuracy)\n",
"\n",
" if i == 0:\n",
" local_max_idx = i\n",
" local_max_test_accuracy = test_accuracy \n",
" if test_accuracy > local_max_test_accuracy:\n",
" local_max_idx = i\n",
" local_max_test_accuracy = test_accuracy\n",
" if test_accuracy > global_max_test_accuracy:\n",
" global_max_test_accuracy = test_accuracy\n",
" lr_op = lr_list_temp[local_max_idx]\n",
" fc_op = fc_list_temp[local_max_idx]\n",
"\n",
" print('Graph Number : ', 10*k+i)\n",
" print('Learning Rate : ', lr_list_temp[i])\n",
" print('FC Number : ', fc_list_temp[i])\n",
" print('Test Accuracy : ', test_accuracy)\n",
" print()\n",
"\n",
" test_accuracy_list = np.array(test_accuracy_list)\n",
" max_index = np.argmax(test_accuracy_list)\n",
"\n",
" print(\"*******************************************\")\n",
" print('Final Graph Number : ', max_index)\n",
" print('Final Learning Rate : ', lr_list[max_index])\n",
" print('Final FC Number : ', fc_list[max_index])\n",
" print('Final Test Accuracy : ', test_accuracy_list[max_index])\n",
" print(\"*******************************************\")\n",
"\n",
" fig = plt.figure()\n",
" ax = plt.gca()\n",
" ax.scatter(lr_list, fc_list, s=100*np.array(test_accuracy_list), c=100*np.array(test_accuracy_list), alpha=0.5)\n",
" ax.set_xscale('log')\n",
" ax.set_xlim([0.0001, 10])\n",
" ax.set_xlabel('learning rate')\n",
" ax.set_ylabel('fc size')\n",
" plt.show()\n",
"\n",
" fig = plt.figure()\n",
" plt.plot(100*np.array(test_accuracy_list))\n",
" plt.xlabel('graph number')\n",
" plt.ylabel('test accuracy')\n",
" plt.show()\n",
"\n",
"\n",
" \" Tuned Model Restoration \"\n",
" tf.reset_default_graph()\n",
" g = tf.Graph() \n",
" with g.as_default():\n",
" with tf.Session(graph=g) as sess:\n",
" saver = tf.train.import_meta_graph('graphs/cnn_fashion_mnist_{}'.format(str(max_index)) + '.meta',\n",
" clear_devices=True)\n",
" saver.restore(sess=sess, save_path='graphs/cnn_fashion_mnist_{}'.format(str(max_index)))\n",
"\n",
" x = sess.graph.get_tensor_by_name('cnn_fashion_mnist_{}'.format(str(max_index)) +'/'+ 'x:0')\n",
" keep_prob = sess.graph.get_tensor_by_name('cnn_fashion_mnist_{}'.format(str(max_index)) +'/'+ 'keep_prob:0')\n",
" is_train = sess.graph.get_tensor_by_name('cnn_fashion_mnist_{}'.format(str(max_index)) +'/'+ 'is_train:0')\n",
" y_pred = sess.graph.get_tensor_by_name('cnn_fashion_mnist_{}'.format(str(max_index)) +'/'+ 'y_pred:0')\n",
"\n",
" feed_dict = {x: x_test, keep_prob: 1.0, is_train: False}\n",
" probs = sess.run(y_pred, feed_dict=feed_dict)\n",
" cls_pred = np.argmax(probs, axis=1)\n",
" print(\"Accuracy on test-set: {:%}\".format((cls_pred == y_test_cls).sum() / len(y_test_cls)))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def drawing_plot():\n",
"\n",
" lr_list = [1.356758973926548, 0.00038223081941407295, 0.0015988830003858152, 0.0013027584733828143, 0.28518258763476456, 0.11306520715540332, 0.0015045871266328773, 0.0020147914418210413, 0.014071335349912242, 0.007213745647375444, 0.0012047054560753241, 0.0011423787471519168, 0.003751660325823518, 0.003644603538620112, 0.0027830712192118906, 0.0036435629949047553, 0.0010087351040689715, 0.0016485846677221948, 0.0025014319290680366, 0.003693579932980143, 0.0008447177473646829, 0.0007685350316084989, 0.0007316903600162763, 0.000987829178213279, 0.0008394687753621476, 0.0012449019424138382, 0.0016685632626670566, 0.001132200744010479, 0.0013144330677903066, 0.0007670630586493807, 0.0010845466361662627, 0.0014883191659676722, 0.001079883231160134, 0.0012419451032611838, 0.0009540670805028198, 0.0015898028663957234, 0.0010908898424281646, 0.0009502969706977384, 0.0010991449523048368, 0.0015741487630427072, 0.00130798326101584, 0.000966614984416173, 0.0010729808507452432, 0.001310284692738252, 0.0010864880290187924, 0.0009909041063364547, 0.0010084137132501843, 0.001087178719144572, 0.0012065830340801987, 0.000994812674878337, 0.0009812586226815147, 0.0011683683212173547, 0.0012151853290298443, 0.0012277923575033478, 0.001214209078450662, 0.0010665320693002335, 0.001182761986509669, 0.0010917016092509924, 0.0009702271750335613, 0.0011409367446231534, 0.001015568136762077, 0.0010786167149631168, 0.0011754067793997315, 0.001139016025194354, 0.0010104187773854545, 0.0011597376554713223, 0.0010375320616265503, 0.0010922714266676235, 0.0011663407133838196, 0.001066679001300662, 0.0011794622423420417, 0.0010369157166564803, 0.001072548182462138, 0.0010352180662965237, 0.0011108792614889942, 0.0010230590104110438, 0.0010780917199593105, 0.0011198746154446008, 0.0010681957955255988, 0.0011664386971175476, 0.0011571580233665723, 0.00109812049756681, 0.0010531384551918496, 0.0011410962428551428, 0.0010438853079804034, 0.0011113845347220886, 0.0011261113393574058, 0.0010728968600661876, 0.0010829457706046247, 0.001052265726017857, 0.0011049872109192606, 0.001106948034414764, 0.0011202463903452718, 0.00113367954899668, 0.0010603857490566534, 0.0011483751375093848, 0.0011173882577890544, 0.001130562304396816, 0.00109621000988208, 0.0011204325659005137]\n",
"\n",
" fc_list = [793, 575, 1265, 697, 405, 1283, 834, 1334, 439, 1310, 701, 735, 871, 971, 642, 472, 827, 737, 496, 590, 607, 664, 1071, 315, 756, 477, 301, 744, 913, 373, 529, 737, 591, 970, 816, 811, 603, 577, 529, 378, 460, 624, 255, 295, 718, 751, 417, 366, 304, 390, 465, 583, 279, 511, 357, 683, 470, 366, 453, 615, 709, 665, 509, 361, 341, 578, 495, 512, 691, 567, 471, 656, 575, 659, 438, 478, 673, 565, 625, 513, 619, 458, 440, 528, 589, 460, 556, 437, 556, 556, 523, 506, 569, 517, 484, 508, 482, 501, 556, 565]\n",
"\n",
" test_accuracy_list = [0.1, 0.8786, 0.897, 0.8967, 0.1, 0.1, 0.8983, 0.8958, 0.8622, 0.8816, 0.899, 0.8953, 0.888, 0.8853, 0.8866, 0.8927, 0.8979, 0.8915, 0.8975, 0.8892, 0.8952, 0.8918, 0.8962, 0.8911, 0.8901, 0.8889, 0.899, 0.8889, 0.8938, 0.8913, 0.8979, 0.8967, 0.8936, 0.8934, 0.8944, 0.895, 0.8942, 0.8896, 0.9001, 0.8932, 0.895, 0.8959, 0.8934, 0.8922, 0.897, 0.8979, 0.8948, 0.8944, 0.892, 0.8917, 0.8943, 0.8933, 0.8943, 0.8896, 0.8942, 0.8964, 0.8951, 0.8918, 0.8913, 0.8914, 0.8918, 0.8934, 0.8898, 0.8876, 0.8915, 0.8923, 0.8899, 0.8929, 0.8853, 0.8946, 0.8924, 0.8951, 0.8949, 0.8947, 0.8946, 0.8892, 0.8954, 0.894, 0.8909, 0.8942, 0.8926, 0.8961, 0.8932, 0.889, 0.8931, 0.8944, 0.8926, 0.894, 0.8915, 0.8982, 0.8983, 0.8922, 0.8971, 0.8935, 0.8944, 0.898, 0.8896, 0.8903, 0.8942, 0.8936]\n",
"\n",
" fig = plt.figure()\n",
" ax = plt.gca()\n",
" ax.scatter(lr_list, fc_list, s=100*np.array(test_accuracy_list), c=100*np.array(test_accuracy_list), alpha=0.5)\n",
" ax.set_xscale('log')\n",
" ax.set_xlim([0.0001, 10])\n",
" ax.set_xlabel('learning rate')\n",
" ax.set_ylabel('fc size')\n",
" plt.show()\n",
"\n",
" fig = plt.figure()\n",
" plt.plot(100*np.array(test_accuracy_list))\n",
" plt.xlabel('graph number')\n",
" plt.ylabel('test accuracy')\n",
" plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 연습문제\n",
"\n",
"비디오\n",
"Multithreading and Multiprocessing by codebasics \n",
"[26](https://www.youtube.com/watch?v=PJ4t2U15ACo)\n",
"[add_on](https://www.youtube.com/watch?v=oIN488Ldg9k)\n",
"[27](https://www.youtube.com/watch?time_continue=3&v=Lu5LrKh1Zno)\n",
"[28](https://www.youtube.com/watch?v=uWbSc84he2Q&index=3&list=PLeo1K3hjS3uub3PRhdoCTY8BxMKSW7RjN)\n",
"[29](https://www.youtube.com/watch?v=sp7EhjLkFY4&index=4&list=PLeo1K3hjS3uub3PRhdoCTY8BxMKSW7RjN)\n",
"[30](https://www.youtube.com/watch?v=POL7n754JTc&list=PLeo1K3hjS3uub3PRhdoCTY8BxMKSW7RjN&index=5)\n",
"[31](https://www.youtube.com/watch?v=_1ZwkCY9wxk&list=PLeo1K3hjS3uub3PRhdoCTY8BxMKSW7RjN&index=6)을 참조, \n",
"위 코드를 멀티프로세싱을 이용하도록 바꾸시오. "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"p2 is runing\n",
"p1 is runing\n",
"p3 is runing\n",
"p4 is runing\n",
"0 14.398005\n",
"0 10.30954\n",
"0 26.218945\n",
"0 20.072233\n",
"100 0.408729\n",
"100 0.36676466\n",
"100 0.42223942\n",
"100 0.3648978\n",
"200 0.41031742\n",
"200 0.40103018\n",
"200 0.36653537\n",
"200 0.30421922\n",
"300 0.34737757\n",
"300 0.35566515\n",
"300 0.3754412\n",
"300 0.35060987\n",
"400 0.3564597\n",
"400 0.35772696\n",
"400 0.3857985\n",
"400 0.31237108\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-59176d61f6a2>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0mpool\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmultiprocessing\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mPool\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mprocesses\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;31m# pool.map(count, process_list)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 16\u001b[0;31m \u001b[0mpool\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhyperparameter_training\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mprocess_list\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 17\u001b[0m \u001b[0mpool\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[0mpool\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/anaconda3/lib/python3.6/multiprocessing/pool.py\u001b[0m in \u001b[0;36mmap\u001b[0;34m(self, func, iterable, chunksize)\u001b[0m\n\u001b[1;32m 264\u001b[0m \u001b[0;32min\u001b[0m \u001b[0ma\u001b[0m \u001b[0mlist\u001b[0m \u001b[0mthat\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0mreturned\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 265\u001b[0m '''\n\u001b[0;32m--> 266\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_map_async\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0miterable\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmapstar\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mchunksize\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 267\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 268\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mstarmap\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0miterable\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mchunksize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/anaconda3/lib/python3.6/multiprocessing/pool.py\u001b[0m in \u001b[0;36mget\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 636\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 637\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 638\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 639\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mready\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 640\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0mTimeoutError\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/anaconda3/lib/python3.6/multiprocessing/pool.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 633\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 634\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 635\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_event\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 636\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 637\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtimeout\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/anaconda3/lib/python3.6/threading.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 549\u001b[0m \u001b[0msignaled\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_flag\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 550\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0msignaled\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 551\u001b[0;31m \u001b[0msignaled\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_cond\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 552\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0msignaled\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 553\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m/anaconda3/lib/python3.6/threading.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 293\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;31m# restore state no matter what (e.g., KeyboardInterrupt)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 294\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 295\u001b[0;31m \u001b[0mwaiter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0macquire\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 296\u001b[0m \u001b[0mgotit\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 297\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"source": [
"import time\n",
"import multiprocessing\n",
"\n",
"start_time = time.time()\n",
"\n",
"# For testing \n",
"def count(name):\n",
" for i in range(1,2001):\n",
" print (name, \" : \", i)\n",
"\n",
"process_list = ['p1', 'p2', 'p3', 'p4']\n",
"\n",
"if __name__ == '__main__': \n",
" pool = multiprocessing.Pool(processes=4)\n",
"# pool.map(count, process_list)\n",
" pool.map(hyperparameter_training, process_list)\n",
" pool.close()\n",
" pool.join()\n",
" print (\"{} seconds\".format(time.time()-start_time))\n",
"# drawing_plot()"
]
}
],
"metadata": {
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment