{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"markdown","source":"Hello lovely folks at/on kaggle, this is my submisssion for the 'Quick, Draw! Doodle Recognition' contest\nI don't know how to acknowledge the use of code from another notebook, and because I\nam new here, Kaggle won't let me contact the ones I want to acknowledge.\nAnyways, I copied some your code @amneves for reading the data, for some reason I have no significant\nexperience in this. The model I am implementing is gonna be completely different from the one I have\nhere right now is just to get myself acquainted with keras. I also tried using some of @kmader code initially\nwhen I was having trouble with the data files."},{"metadata":{"trusted":true,"_uuid":"cc6f6e5946fa690940d47a2aee62202749a76a3d"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"import os\nimport csv\nimport ast\n\nimport numpy as np\nimport pandas as pd\n\nfrom keras.applications import MobileNet\nfrom keras.optimizers   import Adadelta\nfrom keras.losses       import cosine_proximity\nfrom skimage.draw       import line as sk_line\n\n\"\"\"\nI am trying to find why skimage.draw.polygon_perimeter is not working here,\nthis draw.line method I have implemented here is continental-drift slow\n\"\"\"\n\npath2        = '../input/shuffle-csvs/'\npath1        = '../input/train_simplified/'\nclasses_path = os.listdir(path1)\nclasses_path = sorted(classes_path, key = lambda s: s.lower())\nlabels       = {x[:-4].replace(\" \", \"_\") for i, x in enumerate(classes_path)}\n\nsize       = 256\nbatchsize  = 100\n\nlabl_count = len(labels)\ncanvas     = np.zeros((size, size), dtype = np.float16)\n\ndef CATG(T, no = 0, yes = 1):\n\n    bar = np.unique(T)\n    T2  = np.full(T.shape + bar.shape, no)\n    for t in bar:\n        T2[(np.where(T == t)[0]), np.where(bar == t)[0][0]] = yes\n    #print(T2.shape)#check\n    return T2\n\ndef draw(strokes):\n\n    img = canvas\n    for stroke in strokes:\n        for x in range(1, len(stroke)):\n            img[sk_line(stroke[0][x-1], stroke[1][x-1], stroke[0][x], stroke[1][x])] = 1\n\n    return img\n\ndef images(size, batchsize):\n\n    x = np.empty(0)\n    y = np.empty(0)\n    for clazz in classes_path:\n        filename = os.path.join(path1 + clazz)\n        for df in pd.read_csv(filename, chunksize = batchsize):\n            df['drawing'] = df['drawing'].apply(ast.literal_eval)\n            xt = np.zeros((len(df), size, size))\n            for i, raw_strokes in enumerate(df.drawing.values):\n                xt[i] = draw(raw_strokes)\n            x = np.append(xt.reshape((len(df), size, size, 1)),x)\n            y = np.append(np.asarray([clazz] * batchsize), y)\n\n    return x, CATG(y)\n\n\"\"\"\n----------------------------\nFINALLY FOR THE R-E-A-L PART\n----------------------------\n\"\"\"\n\nepochs    = 15\nrho_1     = 0.00486#(rho = rho)\ntrain_dat = images(size, batchsize)\nSTEPS     = 300\n\nmodel = MobileNet(input_shape = (size, size, 1), alpha = 1.0, weights = None, classes = labl_count)\nmodel.compile(optimizer = 'Adadelta', loss = cosine_proximity)\n\nmodel.fit_generator(train_dat, steps_per_epoch = STEPS, epochs = epochs,\n    verbose = 1)#, validation_data = (x_valid, y_valid))\nmodel.save('model1.hdf5')\nprint(\"done\")\n\"\"\"\n\nvalid_df = pd.read_csv(os.path.join(path1, classes_path[99]),\n    nrows = 30000)\nx_valid = df_to_image_array(valid_df)\ny_valid = keras.utils.to_categorical(valid_df[], num_classes=NCATS)\n\n\"\"\"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}