{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"* Reading + Visualizing data","metadata":{}},{"cell_type":"code","source":"## importing all required libraries \n\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nfrom os import path, listdir\nfrom PIL import Image","metadata":{"execution":{"iopub.status.busy":"2021-05-31T11:27:38.165833Z","iopub.execute_input":"2021-05-31T11:27:38.166423Z","iopub.status.idle":"2021-05-31T11:27:38.170613Z","shell.execute_reply.started":"2021-05-31T11:27:38.166387Z","shell.execute_reply":"2021-05-31T11:27:38.169921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##setting ploting background\nsns.set_theme(\"notebook\")\nsns.set_style( \"white\")\n#sns.set_color_codes(\"\")","metadata":{"execution":{"iopub.status.busy":"2021-05-31T11:27:40.699115Z","iopub.execute_input":"2021-05-31T11:27:40.699678Z","iopub.status.idle":"2021-05-31T11:27:40.704231Z","shell.execute_reply.started":"2021-05-31T11:27:40.699642Z","shell.execute_reply":"2021-05-31T11:27:40.703517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_image_dir =\"../input/bms-molecular-translation/train\"\ntrain_label =\"../input/bms-molecular-translation/train_labels.csv\"\nsample_submission= \"../input/bms-molecular-translation/sample_submission.csv\"","metadata":{"execution":{"iopub.status.busy":"2021-05-31T11:27:42.554562Z","iopub.execute_input":"2021-05-31T11:27:42.555166Z","iopub.status.idle":"2021-05-31T11:27:42.559425Z","shell.execute_reply.started":"2021-05-31T11:27:42.555117Z","shell.execute_reply":"2021-05-31T11:27:42.558325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## Reading data to pandas dataframe\ndf = pd.read_csv( train_label,sep =\",\" )\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2021-05-31T11:27:43.936990Z","iopub.execute_input":"2021-05-31T11:27:43.937384Z","iopub.status.idle":"2021-05-31T11:27:49.375262Z","shell.execute_reply.started":"2021-05-31T11:27:43.937346Z","shell.execute_reply":"2021-05-31T11:27:49.374536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## constructing path for all images in the training set\ndf[\"path\"] = df[\"image_id\"].apply( lambda x: train_image_dir +\"/\"+x[0]+\"/\"+x[1]+\"/\"+x[2]+\"/\"+x+\".png\")","metadata":{"execution":{"iopub.status.busy":"2021-05-31T11:28:02.475584Z","iopub.execute_input":"2021-05-31T11:28:02.475928Z","iopub.status.idle":"2021-05-31T11:28:04.956838Z","shell.execute_reply.started":"2021-05-31T11:28:02.475897Z","shell.execute_reply":"2021-05-31T11:28:04.955685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## check path constructed is correct or not for few images\n\nfor x in range( 0, 10 ):\n    random_file = df[\"path\"][np.random.randint( df.shape[0] ) ]\n    if( path.exists ( random_file)):\n        print (\"file exist..>!\")\n    else:\n        print ( \"file doesn'texists = {}\".format( random_file ))","metadata":{"execution":{"iopub.status.busy":"2021-05-31T11:28:04.958865Z","iopub.execute_input":"2021-05-31T11:28:04.959214Z","iopub.status.idle":"2021-05-31T11:28:05.065820Z","shell.execute_reply.started":"2021-05-31T11:28:04.959174Z","shell.execute_reply":"2021-05-31T11:28:05.064991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Let me visualize few image + respective checmical formula\ndef dispaly_image( image_path, caption ):\n    fig = plt.figure( figsize = ( 8,8 ), dpi = 90 )\n    fig.suptitle(\"Chemical Formula = {}\".format ( caption ) )\n    plt.imshow( Image.open( image_path ) )\n    plt.tight_layout()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2021-05-31T11:30:37.093080Z","iopub.execute_input":"2021-05-31T11:30:37.093466Z","iopub.status.idle":"2021-05-31T11:30:37.098966Z","shell.execute_reply.started":"2021-05-31T11:30:37.093432Z","shell.execute_reply":"2021-05-31T11:30:37.097663Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in range( 0, 4) :\n    image_file, caption = df[[\"path\",\"InChI\"]].iloc[ np.random.randint( df.shape[0] ) ]\n    dispaly_image ( image_file, caption )","metadata":{"execution":{"iopub.status.busy":"2021-05-31T11:30:38.916877Z","iopub.execute_input":"2021-05-31T11:30:38.917388Z","iopub.status.idle":"2021-05-31T11:30:41.345030Z","shell.execute_reply.started":"2021-05-31T11:30:38.917353Z","shell.execute_reply":"2021-05-31T11:30:41.344055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2021-05-31T11:28:13.529331Z","iopub.execute_input":"2021-05-31T11:28:13.529675Z","iopub.status.idle":"2021-05-31T11:28:13.535948Z","shell.execute_reply.started":"2021-05-31T11:28:13.529644Z","shell.execute_reply":"2021-05-31T11:28:13.534892Z"},"trusted":true},"execution_count":null,"outputs":[]}]}