{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom keras.models import load_model\nfrom keras.preprocessing import image\nfrom keras.preprocessing.image import load_img,img_to_array\nimport glob\n\nimport cv2\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os        \n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model_path='../input/driverdetectionmodel/model (4).h5'\nmodel = load_model(model_path)\nmodel.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"df = pd.DataFrame({'img':[],'c0':[], 'c1':[],'c2':[], 'c3':[], 'c4':[],'c5':[], 'c6':[], 'c7':[], 'c8':[], 'c9':[]})\ndef _submission(pathPropagate_Images,df):\n    model = load_model(model_path)\n    model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['accuracy'])\n    for imgs in glob.glob(os.path.join(pathPropagate_Images,'*.jpg')):\n        img_cv = cv2.imread(imgs)\n        img_cv_r = cv2.resize(img_cv,(128,128))\n        img_cv_predict = np.reshape(img_cv_r,[1,128,128,3])\n        arr_predict = model.predict(img_cv_predict,batch_size = 1)\n        #print(imgs.split('/')[-1])\n        df = df.append(\n            {\n                'img':imgs.split('/')[-1],\n                'c0':round(arr_predict[0][0],2), \n                'c1':round(arr_predict[0][1],2),\n                'c2':round(arr_predict[0][2],2),\n                'c3':round(arr_predict[0][3],2),\n                'c4':round(arr_predict[0][4],2),\n                'c5':round(arr_predict[0][5],2),\n                'c6':round(arr_predict[0][6],2),\n                'c7':round(arr_predict[0][7],2),\n                'c8':round(arr_predict[0][8],2),\n                'c9':round(arr_predict[0][9],2)\n            },\n            ignore_index=True\n        )\n    return df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pathPropagate_Images =  \"../input/state-farm-distracted-driver-detection/imgs/test/\"\ndf = _submission(pathPropagate_Images,df)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df.to_csv('submission_file.csv',index = False)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}