{"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":"## File and Field Descriptions\n\n### **train/annotations/** Collection of JSON image annotations describing the figures.\n#### source Whether generated or extracted.\n#### chart-type One of dot, horizontal_bar, vertical_bar, line, scatter.\n#### plot-bb Bounding box of the plot within the figure, given by height, width, x0, and y0.\n#### text/id Identifier for a text item within the figure.\n#### text/polygon Region bounding the text item in the image.\n#### text/text The text itself.\n#### text/role The function of the text in the image, whether chart_title, axis_title, tick_label, etc.\n#### axes/{x|y}-axis/ticks/id Identifier matching the tick to the associated text element id.\n#### axes/{x|y}-axis/ticks/tick_pt Coordinates of each tick in the figure.\n#### axes/{x|y}-axis/tick-type The graphical depiction of the tick element.\n#### axes/{x|y}-axis/values-type The data type of the values represented by the tick element, whether categorical or numerical. This field determines how the predicted data series are scored. See the Evaluation page for more information.\n#### visual-elements Indicates part of figure representing the data series. Depends on the chart type.\n#### data-series/{x|y} The x and y coordinates of values depicted in the figure. For the test set images, this is the target to be predicted.\n### **train/images/** Collection of figures in JPG format to be used as training data.\n### **test/images/** Collection of figures to be used as test data. Your task is to predict each corresponding data series for the figures in this folder. The public version of this folder contains only a few example images drawn from the training set.\n### **sample_submission.csv** A submission file in the correct format. See the Evaluation page for more details.","metadata":{}},{"cell_type":"code","source":"# pip install fastai","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:17:47.443328Z","iopub.execute_input":"2023-06-02T06:17:47.443669Z","iopub.status.idle":"2023-06-02T06:17:47.449817Z","shell.execute_reply.started":"2023-06-02T06:17:47.44364Z","shell.execute_reply":"2023-06-02T06:17:47.448776Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport cv2\nimport json\nimport os\nimport cv2\nimport PIL\nimport matplotlib.pyplot as plt \nimport matplotlib.image as mpimg\nfrom pathlib import Path\nimport random\nfrom fastai.vision.all import *","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:17:47.451758Z","iopub.execute_input":"2023-06-02T06:17:47.452111Z","iopub.status.idle":"2023-06-02T06:17:53.921645Z","shell.execute_reply.started":"2023-06-02T06:17:47.45208Z","shell.execute_reply":"2023-06-02T06:17:53.920692Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### from fastai.vision.all import *\n\n#### the classes, functions, and variables from the vision module of the fastai library. This allows you to directly access and use those imported items without explicitly mentioning their module names.\n\n#### When you import the **vision** module from fastai, you gain access to various functionalities related to computer vision tasks, such as image classification, object detection, image segmentation, and more. The vision module provides a high-level API built on top of PyTorch, simplifying the process of working with image data and training deep learning models for computer vision tasks.\n\n#### By using the wildcard character (*), you import all the contents of the vision module into the current namespace. This means you can directly call functions, use classes, or access variables defined within the vision module without explicitly specifying the module name.\n\n##### For example, after importing with from **fastai.vision import *****, you can directly use functions like **ImageDataLoaders**, cnn_learner, or show_batch. Similarly, you can use classes like DataBlock, Learner, or untar_data without needing to prefix them with vision..","metadata":{}},{"cell_type":"code","source":"annotations  = Path(\"/kaggle/input/benetech-making-graphs-accessible/train/annotations\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:17:53.924538Z","iopub.execute_input":"2023-06-02T06:17:53.925268Z","iopub.status.idle":"2023-06-02T06:17:53.929695Z","shell.execute_reply.started":"2023-06-02T06:17:53.925233Z","shell.execute_reply":"2023-06-02T06:17:53.928513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = Path(\"/kaggle/input/benetech-making-graphs-accessible/train/images\")\ntest  = Path(\"/kaggle/input/benetech-making-graphs-accessible/test/images\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:17:53.931162Z","iopub.execute_input":"2023-06-02T06:17:53.931524Z","iopub.status.idle":"2023-06-02T06:17:53.941762Z","shell.execute_reply.started":"2023-06-02T06:17:53.931491Z","shell.execute_reply":"2023-06-02T06:17:53.940908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/train/images/0005413054c9.jpg')\n# print(sh)\nprint(sh.shape)\nimplt = plt.imshow(sh)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:17:53.944551Z","iopub.execute_input":"2023-06-02T06:17:53.945013Z","iopub.status.idle":"2023-06-02T06:17:54.258704Z","shell.execute_reply.started":"2023-06-02T06:17:53.944981Z","shell.execute_reply":"2023-06-02T06:17:54.257786Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_dir = '/kaggle/input/benetech-making-graphs-accessible/train/images'\nimage_files = os.listdir(image_dir)\nnum_rows = 2\nnum_cols = 3\nfig, axes = plt.subplots(num_rows, num_cols, figsize=(12, 8))\nfor i, ax in enumerate(axes.flat):\n    if i < len(image_files):\n        image_path = os.path.join(image_dir, image_files[i])\n        image = plt.imread(image_path)\n        \n        ax.imshow(image)\n        ax.axis('off')\n    else:\n        fig.delaxes(ax)\n\nplt.tight_layout()\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:17:54.259655Z","iopub.execute_input":"2023-06-02T06:17:54.259982Z","iopub.status.idle":"2023-06-02T06:17:55.510905Z","shell.execute_reply.started":"2023-06-02T06:17:54.259951Z","shell.execute_reply":"2023-06-02T06:17:55.510106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### *dict_ = dict(): This initializes an empty dictionary named dict_.\n\n#### *file_name in os.listdir(annotations):: This loop iterates over the files in the directory specified by the variable annotations. os.listdir(annotations) returns a list of filenames within that directory.\n\n #### *image_idx = file_name.split('.')[0]: This line extracts the image index from the file_name by splitting it at the period ('.') and taking the first element of the resulting list. This assumes that the file names follow a pattern where the index is the part before the first period.\n\n#### *dict_[image_idx] = json.load(open(annotations/file_name)): This line loads the JSON data from the file and assigns it as the value for the image_idx key in the dictionary dict_. The json.load() function reads the contents of the file, and open(annotations/file_name) opens the file in read mode.","metadata":{}},{"cell_type":"code","source":"dict_ = dict()\nfor file_name in os.listdir(annotations):  \n    image_idx = file_name.split('.')[0]\n    dict_[image_idx] = json.load(open(annotations/file_name))","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:17:55.512074Z","iopub.execute_input":"2023-06-02T06:17:55.519257Z","iopub.status.idle":"2023-06-02T06:21:07.914708Z","shell.execute_reply.started":"2023-06-02T06:17:55.519225Z","shell.execute_reply":"2023-06-02T06:21:07.913748Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_f = pd.DataFrame.from_dict(dict_, orient=\"index\")\nd_f.head()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:07.918577Z","iopub.execute_input":"2023-06-02T06:21:07.918857Z","iopub.status.idle":"2023-06-02T06:21:08.439396Z","shell.execute_reply.started":"2023-06-02T06:21:07.918833Z","shell.execute_reply":"2023-06-02T06:21:08.437119Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_f['chart-type'].head()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.440901Z","iopub.execute_input":"2023-06-02T06:21:08.441377Z","iopub.status.idle":"2023-06-02T06:21:08.452032Z","shell.execute_reply.started":"2023-06-02T06:21:08.441332Z","shell.execute_reply":"2023-06-02T06:21:08.451113Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(d_f['chart-type'])\nprint(len(d_f['chart-type']))","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.453874Z","iopub.execute_input":"2023-06-02T06:21:08.454245Z","iopub.status.idle":"2023-06-02T06:21:08.480606Z","shell.execute_reply.started":"2023-06-02T06:21:08.454212Z","shell.execute_reply":"2023-06-02T06:21:08.479469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" ### the following column name changes are being made:\n\n**'chart-type'** is being renamed to 'chart_type'\n\n**'plot-bb'** is being renamed to 'plot_bb'\n\n**'data-series**' is being renamed to 'data_series'\n\n**'axes'** is being renamed to 'xy_axes'","metadata":{}},{"cell_type":"code","source":"d_f.rename(columns = {'chart-type':'chart_type', 'plot-bb'   :'plot_bb' ,'data-series':'data_series', 'axes':'xy_axes'} , inplace=True)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.48545Z","iopub.execute_input":"2023-06-02T06:21:08.486115Z","iopub.status.idle":"2023-06-02T06:21:08.491827Z","shell.execute_reply.started":"2023-06-02T06:21:08.486082Z","shell.execute_reply":"2023-06-02T06:21:08.490922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_f['plot_bb']","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.494141Z","iopub.execute_input":"2023-06-02T06:21:08.494854Z","iopub.status.idle":"2023-06-02T06:21:08.507317Z","shell.execute_reply.started":"2023-06-02T06:21:08.494823Z","shell.execute_reply":"2023-06-02T06:21:08.506322Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_f['data_series']","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.51017Z","iopub.execute_input":"2023-06-02T06:21:08.510523Z","iopub.status.idle":"2023-06-02T06:21:08.544031Z","shell.execute_reply.started":"2023-06-02T06:21:08.510478Z","shell.execute_reply":"2023-06-02T06:21:08.543088Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"This line adds a new column named '**images**' to the DataFrame **d_f_data**. It uses the map() function to apply a **lambda** function to each value in the 'index' column. The lambda function concatenates '.jpg' to each value of 'index'. The resulting values are assigned to the '**images**' column.","metadata":{}},{"cell_type":"code","source":"# d_f['xy_axis']","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.545277Z","iopub.execute_input":"2023-06-02T06:21:08.545621Z","iopub.status.idle":"2023-06-02T06:21:08.549896Z","shell.execute_reply.started":"2023-06-02T06:21:08.545591Z","shell.execute_reply":"2023-06-02T06:21:08.54898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_f_data = d_f.reset_index()\nd_f_data['images'] = d_f_data['index'].map(lambda x: x + '.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.551328Z","iopub.execute_input":"2023-06-02T06:21:08.551944Z","iopub.status.idle":"2023-06-02T06:21:08.599625Z","shell.execute_reply.started":"2023-06-02T06:21:08.551913Z","shell.execute_reply":"2023-06-02T06:21:08.598737Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_f_data = d_f_data.set_index('index')\nd_f_data.head(3)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.602098Z","iopub.execute_input":"2023-06-02T06:21:08.602434Z","iopub.status.idle":"2023-06-02T06:21:08.761863Z","shell.execute_reply.started":"2023-06-02T06:21:08.602404Z","shell.execute_reply":"2023-06-02T06:21:08.760907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_f_data['chart_type'].unique()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.763411Z","iopub.execute_input":"2023-06-02T06:21:08.764048Z","iopub.status.idle":"2023-06-02T06:21:08.78883Z","shell.execute_reply.started":"2023-06-02T06:21:08.764002Z","shell.execute_reply":"2023-06-02T06:21:08.787998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_f_data['xy_axes']","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.789943Z","iopub.execute_input":"2023-06-02T06:21:08.790281Z","iopub.status.idle":"2023-06-02T06:21:08.824846Z","shell.execute_reply.started":"2023-06-02T06:21:08.790251Z","shell.execute_reply":"2023-06-02T06:21:08.824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"these lines create separate index arrays (**vertical_bar_index**, **horizontal_bar_index**, **line_chart_index**, **scatter_plot_index**, and **dot_plot_index**) based on specific conditions defined by the '**chart_type**' column in the DataFrame d_f_data. Each index array contains the row indices where the corresponding chart type is present.","metadata":{}},{"cell_type":"code","source":"vertical_bar_index    = d_f_data[d_f_data.chart_type == 'vertical_bar'].index\nhorizontal_bar_index     = d_f_data[d_f_data.chart_type == 'horizontal_bar'].index\nline_chart_index     = d_f_data[d_f_data.chart_type == 'line_chart'].index\nscatter_plot_index  = d_f_data[d_f_data.chart_type == 'scatter_plot'].index\ndot_plot_index      = d_f_data[d_f_data.chart_type == 'dot_plot'].index","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.826231Z","iopub.execute_input":"2023-06-02T06:21:08.826583Z","iopub.status.idle":"2023-06-02T06:21:08.925402Z","shell.execute_reply.started":"2023-06-02T06:21:08.826553Z","shell.execute_reply":"2023-06-02T06:21:08.924478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vertical_bar_index_val    = random.sample(set(vertical_bar_index) , int(len(vertical_bar_index)*0.2))\nhorizontal_bar_index_val    = random.sample(set(horizontal_bar_index) , int(len(horizontal_bar_index)*0.2))\nline_chart_index_val    = random.sample(set(line_chart_index) , int(len(line_chart_index)*0.2))\nscatter_plot_index_val = random.sample(set(scatter_plot_index) , int(len(scatter_plot_index)*0.2))\ndot_plot_index_val     = random.sample(set(dot_plot_index), int(len(dot_plot_index)*0.2))","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.927013Z","iopub.execute_input":"2023-06-02T06:21:08.927395Z","iopub.status.idle":"2023-06-02T06:21:08.946937Z","shell.execute_reply.started":"2023-06-02T06:21:08.927362Z","shell.execute_reply":"2023-06-02T06:21:08.945897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# d_f_data['xy_axes']","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.948843Z","iopub.execute_input":"2023-06-02T06:21:08.949354Z","iopub.status.idle":"2023-06-02T06:21:08.956658Z","shell.execute_reply.started":"2023-06-02T06:21:08.949292Z","shell.execute_reply":"2023-06-02T06:21:08.955327Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# index_x_axis = d_f_data[d_f_data.xy_axes == 'x_axis']\n# index_y_axis = d_f_data[d_f_data.xy_axes == 'y_axis']","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.958579Z","iopub.execute_input":"2023-06-02T06:21:08.958986Z","iopub.status.idle":"2023-06-02T06:21:08.964617Z","shell.execute_reply.started":"2023-06-02T06:21:08.958952Z","shell.execute_reply":"2023-06-02T06:21:08.963518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# index_x_axis = random.sample(set(index_x_axis), int(len(index_x_axis)))\n# index_y_axis = random.sample(set(index_y_axis), int(len(index_y_axis)))","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.96694Z","iopub.execute_input":"2023-06-02T06:21:08.967254Z","iopub.status.idle":"2023-06-02T06:21:08.974137Z","shell.execute_reply.started":"2023-06-02T06:21:08.967231Z","shell.execute_reply":"2023-06-02T06:21:08.973178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"combining multiple index arrays into a single array **val_idx**. Then, it sets the 'is_valid' column in the DataFrame **d_f_data** to True for the rows with indices specified in **val_idx**, while leaving the rest of the rows with False in the 'is_valid' column.","metadata":{}},{"cell_type":"code","source":"val_idx = vertical_bar_index_val + horizontal_bar_index_val + line_chart_index_val + scatter_plot_index_val + dot_plot_index_val\nd_f_data['is_valid'] = False\nfor idx in val_idx:\n    d_f_data.loc[idx,'is_valid'] = True","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:08.975729Z","iopub.execute_input":"2023-06-02T06:21:08.976409Z","iopub.status.idle":"2023-06-02T06:21:09.279944Z","shell.execute_reply.started":"2023-06-02T06:21:08.976376Z","shell.execute_reply":"2023-06-02T06:21:09.278989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# axis_idx = index_x_axis + index_y_axis\n# for both_idx in axis_idx:\n#     d_f_data.loc[both_idx]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.281612Z","iopub.execute_input":"2023-06-02T06:21:09.281977Z","iopub.status.idle":"2023-06-02T06:21:09.286219Z","shell.execute_reply.started":"2023-06-02T06:21:09.281939Z","shell.execute_reply":"2023-06-02T06:21:09.285319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_f_data.columns","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.287803Z","iopub.execute_input":"2023-06-02T06:21:09.288469Z","iopub.status.idle":"2023-06-02T06:21:09.298709Z","shell.execute_reply.started":"2023-06-02T06:21:09.288434Z","shell.execute_reply":"2023-06-02T06:21:09.297725Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_show = d_f_data[['images','chart_type','is_valid']]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.300265Z","iopub.execute_input":"2023-06-02T06:21:09.300673Z","iopub.status.idle":"2023-06-02T06:21:09.311745Z","shell.execute_reply.started":"2023-06-02T06:21:09.30064Z","shell.execute_reply":"2023-06-02T06:21:09.310835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_show = data_show.rename(columns={'chart_type':'label'})\ndata_show.head()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.314714Z","iopub.execute_input":"2023-06-02T06:21:09.314977Z","iopub.status.idle":"2023-06-02T06:21:09.33408Z","shell.execute_reply.started":"2023-06-02T06:21:09.314954Z","shell.execute_reply":"2023-06-02T06:21:09.333259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_show = d_f_data[['images', 'chart_type', 'xy_axes', 'data_series', 'is_valid']]\ndata_show = data_show.rename(columns={'chart_type': 'label'})","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.342516Z","iopub.execute_input":"2023-06-02T06:21:09.342777Z","iopub.status.idle":"2023-06-02T06:21:09.3647Z","shell.execute_reply.started":"2023-06-02T06:21:09.342753Z","shell.execute_reply":"2023-06-02T06:21:09.363838Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_show","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.365929Z","iopub.execute_input":"2023-06-02T06:21:09.366293Z","iopub.status.idle":"2023-06-02T06:21:09.453783Z","shell.execute_reply.started":"2023-06-02T06:21:09.36626Z","shell.execute_reply":"2023-06-02T06:21:09.452847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# dls = ImageDataLoaders.from_df(data_show, train , valid_col='is_valid' , item_tfms=Resize(224))","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.455142Z","iopub.execute_input":"2023-06-02T06:21:09.455611Z","iopub.status.idle":"2023-06-02T06:21:09.4601Z","shell.execute_reply.started":"2023-06-02T06:21:09.455577Z","shell.execute_reply":"2023-06-02T06:21:09.459108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# dls.show_batch(max_n=12)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.46182Z","iopub.execute_input":"2023-06-02T06:21:09.462596Z","iopub.status.idle":"2023-06-02T06:21:09.468834Z","shell.execute_reply.started":"2023-06-02T06:21:09.462556Z","shell.execute_reply":"2023-06-02T06:21:09.467876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_y(r):\n    axes = json.loads(r['xy_axes'])\n    data_series = json.loads(r['data_series'])\n    return {\n        'chart_type': r['label'],\n        'x_axis': axes['x-axis'],\n        'y_axis': axes['y-axis'],\n        'ids': [series['id'] for series in data_series]\n    }","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.470598Z","iopub.execute_input":"2023-06-02T06:21:09.470871Z","iopub.status.idle":"2023-06-02T06:21:09.48048Z","shell.execute_reply.started":"2023-06-02T06:21:09.470848Z","shell.execute_reply":"2023-06-02T06:21:09.479493Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls_2 = ImageDataLoaders.from_df(data_show, train, valid_col='is_valid', item_tfms=Resize(224), get_y=get_y, y_col=['chart_type', 'x_axis', 'y_axis', 'ids'])","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:09.48188Z","iopub.execute_input":"2023-06-02T06:21:09.482924Z","iopub.status.idle":"2023-06-02T06:21:18.352603Z","shell.execute_reply.started":"2023-06-02T06:21:09.482848Z","shell.execute_reply":"2023-06-02T06:21:18.351606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict = vision_learner(dls_2, resnet34, metrics=error_rate)\npredict.fine_tune(1)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:21:18.356711Z","iopub.execute_input":"2023-06-02T06:21:18.35701Z","iopub.status.idle":"2023-06-02T06:34:55.551964Z","shell.execute_reply.started":"2023-06-02T06:21:18.356984Z","shell.execute_reply":"2023-06-02T06:34:55.55084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_dl = '/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg'\n# test_dl = dls_2.test_dl('/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:55.556633Z","iopub.execute_input":"2023-06-02T06:34:55.558909Z","iopub.status.idle":"2023-06-02T06:34:55.564965Z","shell.execute_reply.started":"2023-06-02T06:34:55.558868Z","shell.execute_reply":"2023-06-02T06:34:55.564138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from PIL import Image\nimport torch","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:55.56985Z","iopub.execute_input":"2023-06-02T06:34:55.571378Z","iopub.status.idle":"2023-06-02T06:34:55.578735Z","shell.execute_reply.started":"2023-06-02T06:34:55.571344Z","shell.execute_reply":"2023-06-02T06:34:55.577752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pip install transformers","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:55.581123Z","iopub.execute_input":"2023-06-02T06:34:55.582105Z","iopub.status.idle":"2023-06-02T06:34:55.588113Z","shell.execute_reply.started":"2023-06-02T06:34:55.582071Z","shell.execute_reply":"2023-06-02T06:34:55.58709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import transformers\nfrom torchvision import transforms","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:55.590763Z","iopub.execute_input":"2023-06-02T06:34:55.592Z","iopub.status.idle":"2023-06-02T06:34:56.852536Z","shell.execute_reply.started":"2023-06-02T06:34:55.591966Z","shell.execute_reply":"2023-06-02T06:34:56.851513Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Test image path\n# test_image = '/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg'\n# # Load the test image\n# test_img = PIL.Image.open(test_image)\n# # Preprocess the test image\n# test_img_resized = test_img.resize((224, 224))  # Resize to match the model input size\n# test_img_tensor = ToTensor()(test_img_resized)  # Convert to tensor","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:56.857396Z","iopub.execute_input":"2023-06-02T06:34:56.861112Z","iopub.status.idle":"2023-06-02T06:34:56.867617Z","shell.execute_reply.started":"2023-06-02T06:34:56.861072Z","shell.execute_reply":"2023-06-02T06:34:56.866679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Make a prediction on the test image\n# pred = predict.predict(test_img_tensor)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:56.872626Z","iopub.execute_input":"2023-06-02T06:34:56.875444Z","iopub.status.idle":"2023-06-02T06:34:56.881247Z","shell.execute_reply.started":"2023-06-02T06:34:56.875409Z","shell.execute_reply":"2023-06-02T06:34:56.880225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Extract the predicted values\n# chart_type_pred = pred[0]  # Predicted chart type\n# x_axis_pred = pred[1]  # Predicted X-axis\n# y_axis_pred = pred[2]  # Predicted Y-axis\n# ids_pred = pred[3]  # Predicted IDs","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:56.885926Z","iopub.execute_input":"2023-06-02T06:34:56.887137Z","iopub.status.idle":"2023-06-02T06:34:56.892546Z","shell.execute_reply.started":"2023-06-02T06:34:56.887104Z","shell.execute_reply":"2023-06-02T06:34:56.891633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pip install easyocr","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:56.895143Z","iopub.execute_input":"2023-06-02T06:34:56.896252Z","iopub.status.idle":"2023-06-02T06:34:56.902802Z","shell.execute_reply.started":"2023-06-02T06:34:56.896218Z","shell.execute_reply":"2023-06-02T06:34:56.901889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import easyocr","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:56.90549Z","iopub.execute_input":"2023-06-02T06:34:56.906277Z","iopub.status.idle":"2023-06-02T06:34:57.380384Z","shell.execute_reply.started":"2023-06-02T06:34:56.906244Z","shell.execute_reply":"2023-06-02T06:34:57.379363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# image one","metadata":{}},{"cell_type":"code","source":"image_path_1 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg\"\nimage = cv2.imread(image_path_1)\npred = predict.predict(image_path_1)\n# Extract the predicted values\nchart_type_pred_1 = pred[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_1)\nreader = easyocr.Reader(['en'])\nresults = reader.readtext(image, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\nx_axis_values = []\ny_axis_values = []\nx_axis_values = results[3:]\ny_axis_values = results[:3]\nprint(\"X-axis values:\", x_axis_values)\nprint(\"Y-axis values:\", y_axis_values)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:34:57.385432Z","iopub.execute_input":"2023-06-02T06:34:57.387771Z","iopub.status.idle":"2023-06-02T06:35:03.019353Z","shell.execute_reply.started":"2023-06-02T06:34:57.387733Z","shell.execute_reply":"2023-06-02T06:35:03.018196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# image two","metadata":{}},{"cell_type":"code","source":"image_path_2 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg\"\nimage_2 = cv2.imread(image_path_2)\npred_2 = predict.predict(image_path_2)\n# Extract the predicted values\nchart_type_pred_2 = pred_2[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_2)\nreader_2 = easyocr.Reader(['en'])\nresults_2 = reader_2.readtext(image_2, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\nx_axis_values_2 = []\ny_axis_values_2 = []\ny_axis_values_2 = results_2[1:6]\nx_axis_values_2 = results_2[6:]\nprint(\"X-axis values:\", x_axis_values_2)\nprint(\"Y-axis values:\", y_axis_values_2)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:35:03.023674Z","iopub.execute_input":"2023-06-02T06:35:03.026725Z","iopub.status.idle":"2023-06-02T06:35:07.685325Z","shell.execute_reply.started":"2023-06-02T06:35:03.026686Z","shell.execute_reply":"2023-06-02T06:35:07.684356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Image three","metadata":{}},{"cell_type":"code","source":"image_path_3 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/00dcf883a459.jpg\"\nimage_3 = cv2.imread(image_path_3)\npred_3 = predict.predict(image_path_3)\n# Extract the predicted values\nchart_type_pred_3 = pred_3[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_3)\nreader_3 = easyocr.Reader(['en'])\nresults_3 = reader_3.readtext(image_3, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\n# print(results_3)\nx_axis_values_3 = []\ny_axis_values_3 = []\nx_axis_values_3 = results_3[2:]\ny_axis_values_3 = results_3[:1]\nprint(\"X-axis values:\", x_axis_values_3)\nprint(\"Y-axis values:\", y_axis_values_3)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:35:07.689627Z","iopub.execute_input":"2023-06-02T06:35:07.691862Z","iopub.status.idle":"2023-06-02T06:35:12.349905Z","shell.execute_reply.started":"2023-06-02T06:35:07.691826Z","shell.execute_reply":"2023-06-02T06:35:12.34895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_path_4 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/00f5404753cf.jpg\"\nimage_4 = cv2.imread(image_path_4)\npred_4 = predict.predict(image_path_4)\n# Extract the predicted values\nchart_type_pred_4 = pred_4[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_4)\nreader_4 = easyocr.Reader(['en'])\nresults_4 = reader_4.readtext(image_4, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\nprint(results_4)\nx_axis_values_4 = []\ny_axis_values_4 = []\nx_axis_values_4 = results_4[:2]\ny_axis_values_4 = results_4[2:]\nprint(\"X-axis values:\", x_axis_values_4)\nprint(\"Y-axis values:\", y_axis_values_4)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:35:12.354508Z","iopub.execute_input":"2023-06-02T06:35:12.357091Z","iopub.status.idle":"2023-06-02T06:35:17.537849Z","shell.execute_reply.started":"2023-06-02T06:35:12.357012Z","shell.execute_reply":"2023-06-02T06:35:17.536899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Image five","metadata":{}},{"cell_type":"code","source":"image_path_5 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg\"\nimage_5 = cv2.imread(image_path_5)\npred_5 = predict.predict(image_path_5)\n# Extract the predicted values\nchart_type_pred_5 = pred_2[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_5)\nreader_5 = easyocr.Reader(['en'])\nresults_5 = reader_5.readtext(image_5, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\nx_axis_values_5 = []\ny_axis_values_5 = []\ny_axis_values_5 = results_5[1:6]\nx_axis_values_5 = results_5[6:]\nprint(\"X-axis values:\", x_axis_values_5)\nprint(\"Y-axis values:\", y_axis_values_5)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:35:17.542182Z","iopub.execute_input":"2023-06-02T06:35:17.544425Z","iopub.status.idle":"2023-06-02T06:35:22.329487Z","shell.execute_reply.started":"2023-06-02T06:35:17.544386Z","shell.execute_reply":"2023-06-02T06:35:22.328498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# ids_pred = ids_pred.tolist()  # Convert to list\n# chart_type_pred = chart_type_pred.numpy()  # Convert to numpy array\n# x_axis_pred = x_axis_pred.numpy()  # Convert to numpy array\n# y_axis_pred = y_axis_pred.numpy()  # Convert to numpy array","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:35:22.333902Z","iopub.execute_input":"2023-06-02T06:35:22.336609Z","iopub.status.idle":"2023-06-02T06:35:22.342906Z","shell.execute_reply.started":"2023-06-02T06:35:22.336572Z","shell.execute_reply":"2023-06-02T06:35:22.341778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# CNN_LEARNER","metadata":{}},{"cell_type":"markdown","source":"we are using the cnn_learner function to create a convolutional neural network (CNN) model with the ResNet-34 architecture. We specify the data loaders (dls) and the accuracy metric for evaluation.\n\nThe fine_tune method is then called to train the model for 4 epochs. You can adjust the number of epochs based on your specific requirements.\n\nFinally, you can use the show_results method to visualize the results of the trained model.\n\nMake sure you have the necessary dependencies installed and that you have defined the appropriate paths for your data before running the training code.","metadata":{}},{"cell_type":"code","source":"# Define the model architecture\nmodel = cnn_learner(dls_2, resnet34, metrics=accuracy)\n# Train the model\nmodel.fine_tune(4)\n# Evaluate the model","metadata":{"execution":{"iopub.status.busy":"2023-06-02T06:35:22.347585Z","iopub.execute_input":"2023-06-02T06:35:22.348692Z","iopub.status.idle":"2023-06-02T07:02:26.813425Z","shell.execute_reply.started":"2023-06-02T06:35:22.348655Z","shell.execute_reply":"2023-06-02T07:02:26.812301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# image one","metadata":{}},{"cell_type":"code","source":"image_path_1 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg\"\nimage = cv2.imread(image_path_1)\npred = model.predict(image_path_1)\n# Extract the predicted values\nchart_type_pred_1 = pred[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_1)\nreader = easyocr.Reader(['en'])\nresults = reader.readtext(image, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\nx_axis_values = []\ny_axis_values = []\nx_axis_values = results[3:]\ny_axis_values = results[:3]\nprint(\"X-axis values:\", x_axis_values)\nprint(\"Y-axis values:\", y_axis_values)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:26.815484Z","iopub.execute_input":"2023-06-02T07:02:26.815871Z","iopub.status.idle":"2023-06-02T07:02:29.585192Z","shell.execute_reply.started":"2023-06-02T07:02:26.815832Z","shell.execute_reply":"2023-06-02T07:02:29.584072Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# image two","metadata":{}},{"cell_type":"code","source":"image_path_2 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg\"\nimage_2 = cv2.imread(image_path_2)\npred_2 = model.predict(image_path_2)\n# Extract the predicted values\nchart_type_pred_2 = pred_2[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_2)\nreader_2 = easyocr.Reader(['en'])\nresults_2 = reader_2.readtext(image_2, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\nx_axis_values_2 = []\ny_axis_values_2 = []\ny_axis_values_2 = results_2[1:6]\nx_axis_values_2 = results_2[6:]\nprint(\"X-axis values:\", x_axis_values_2)\nprint(\"Y-axis values:\", y_axis_values_2)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:29.586665Z","iopub.execute_input":"2023-06-02T07:02:29.588348Z","iopub.status.idle":"2023-06-02T07:02:32.31575Z","shell.execute_reply.started":"2023-06-02T07:02:29.588297Z","shell.execute_reply":"2023-06-02T07:02:32.314671Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# image 3 ","metadata":{}},{"cell_type":"code","source":"image_path_3 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/00dcf883a459.jpg\"\nimage_3 = cv2.imread(image_path_3)\npred_3 = model.predict(image_path_3)\n# Extract the predicted values\nchart_type_pred_3 = pred_3[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_3)\nreader_3 = easyocr.Reader(['en'])\nresults_3 = reader_3.readtext(image_3, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\n# print(results_3)\nx_axis_values_3 = []\ny_axis_values_3 = []\nx_axis_values_3 = results_3[2:]\ny_axis_values_3 = results_3[:1]\nprint(\"X-axis values:\", x_axis_values_3)\nprint(\"Y-axis values:\", y_axis_values_3)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:32.317115Z","iopub.execute_input":"2023-06-02T07:02:32.318023Z","iopub.status.idle":"2023-06-02T07:02:34.944018Z","shell.execute_reply.started":"2023-06-02T07:02:32.317986Z","shell.execute_reply":"2023-06-02T07:02:34.942839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# image 4","metadata":{}},{"cell_type":"code","source":"image_path_4 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/00f5404753cf.jpg\"\nimage_4 = cv2.imread(image_path_4)\npred_4 = model.predict(image_path_4)\n# Extract the predicted values\nchart_type_pred_4 = pred_4[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_4)\nreader_4 = easyocr.Reader(['en'])\nresults_4 = reader_4.readtext(image_4, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\nprint(results_4)\nx_axis_values_4 = []\ny_axis_values_4 = []\nx_axis_values_4 = results_4[:2]\ny_axis_values_4 = results_4[2:]\nprint(\"X-axis values:\", x_axis_values_4)\nprint(\"Y-axis values:\", y_axis_values_4)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:34.945564Z","iopub.execute_input":"2023-06-02T07:02:34.946113Z","iopub.status.idle":"2023-06-02T07:02:37.601071Z","shell.execute_reply.started":"2023-06-02T07:02:34.946054Z","shell.execute_reply":"2023-06-02T07:02:37.599941Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# image five","metadata":{}},{"cell_type":"code","source":"image_path_5 = \"/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg\"\nimage_5 = cv2.imread(image_path_5)\npred_5 = model.predict(image_path_5)\n# Extract the predicted values\nchart_type_pred_5 = pred_2[0]  # Predicted chart type\n# Print the predicted values\nprint(\"Predicted Chart Type:\", chart_type_pred_5)\nreader_5 = easyocr.Reader(['en'])\nresults_5 = reader_5.readtext(image_5, detail=0)\n# Process the OCR results to extract the x-axis and y-axis values\nx_axis_values_5 = []\ny_axis_values_5 = []\ny_axis_values_5 = results_5[1:6]\nx_axis_values_5 = results_5[6:]\nprint(\"X-axis values:\", x_axis_values_5)\nprint(\"Y-axis values:\", y_axis_values_5)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:37.602916Z","iopub.execute_input":"2023-06-02T07:02:37.603296Z","iopub.status.idle":"2023-06-02T07:02:40.426314Z","shell.execute_reply.started":"2023-06-02T07:02:37.60326Z","shell.execute_reply":"2023-06-02T07:02:40.425201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_dir = \"/kaggle/input/benetech-making-graphs-accessible/test/images\"\n","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:40.427608Z","iopub.execute_input":"2023-06-02T07:02:40.427992Z","iopub.status.idle":"2023-06-02T07:02:40.433509Z","shell.execute_reply.started":"2023-06-02T07:02:40.427955Z","shell.execute_reply":"2023-06-02T07:02:40.432272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Get a list of test image files\n# test_files = os.listdir(test_dir)\n# predictions = []","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:40.435428Z","iopub.execute_input":"2023-06-02T07:02:40.43589Z","iopub.status.idle":"2023-06-02T07:02:40.444171Z","shell.execute_reply.started":"2023-06-02T07:02:40.435854Z","shell.execute_reply":"2023-06-02T07:02:40.442924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Loop through the test images and make predictions\n# for file in test_files:\n#     # Load the test image\n#     image_path = os.path.join(test_dir, file)\n#     test_image = PIL.Image.open(image_path)\n    \n#     # Preprocess the image\n#     test_dl = dls_2.test_dl([test_image])\n    \n#     # Make the prediction\n#     pred = predict.predict(test_dl.items)\n    \n#     # Extract the predicted features\n#     chart_type = pred[0]\n#     x_axis = pred[1][0]\n#     y_axis = pred[1][1]\n#     ids = pred[1][2]\n    \n#     # Append the predictions to the list\n#     predictions.append((file, chart_type, x_axis, y_axis, ids))\n# Loop through the test images and make predictions\n\n\n# for file in test_files:\n#     # Load the test image\n#     image_path = os.path.join(test_dir, file)\n#     test_image = PIL.Image.open(image_path)\n    \n#     # Preprocess the image\n#     test_dl = dls_2.test_dl([test_image])\n    \n#     # Make the prediction\n#     pred = predict.predict(test_dl.items[0])\n    \n#     # Extract the predicted features\n#     chart_type = pred[0]\n#     x_axis = pred[1][0]\n#     y_axis = pred[1][1]\n#     ids = pred[1][2]\n    \n#     # Append the predictions to the list\n#     predictions.append((file, chart_type, x_axis, y_axis, ids))\n\n# from PIL import Image\n\n# def load_image(test_files):\n#     try:\n#         img = Image.open(test_files)\n#         return img\n#     except IOError:\n#         print(f\"Unable to load image at: {test_files}\")\n#         return None\n\n# Load the image\n# test_image = load_image(\"path_to_your_image.jpg\")\n\n# if test_image is not None:\n#     # Perform the prediction\n#     pred = predict.predict(test_image)\n#     # Extract the predicted features\n#     chart_type = pred[0]\n#     print(f\"Predicted chart type: {chart_type}\")\n","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:40.4456Z","iopub.execute_input":"2023-06-02T07:02:40.445965Z","iopub.status.idle":"2023-06-02T07:02:40.454464Z","shell.execute_reply.started":"2023-06-02T07:02:40.445915Z","shell.execute_reply":"2023-06-02T07:02:40.453535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# data_show","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:40.456205Z","iopub.execute_input":"2023-06-02T07:02:40.456566Z","iopub.status.idle":"2023-06-02T07:02:40.467329Z","shell.execute_reply.started":"2023-06-02T07:02:40.456534Z","shell.execute_reply":"2023-06-02T07:02:40.466258Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_image = load_image(\"/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg\")\n# pred = predict.predict(test_image)\n# # Extract the predicted features\n# chart_type = pred[0]\n# print(f\"Predicted chart type: {chart_type}\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:40.468517Z","iopub.execute_input":"2023-06-02T07:02:40.469472Z","iopub.status.idle":"2023-06-02T07:02:40.477754Z","shell.execute_reply.started":"2023-06-02T07:02:40.469436Z","shell.execute_reply":"2023-06-02T07:02:40.476847Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model.show_results()\npred_test_2 = predict.predict('/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg')\nprint(pred_test_2)\nchart_type = pred_test_2[0]\naxis_x = pred_test_2[1]\n\nprint(axis_x)\nprint(chart_type)\n# chart_type_1 = pred_test_2[0]\n\n# chart_type_1 = pred_test_2[0]\n# x_axis = pred_test_2[1][0].item()\n# y_axis = pred[1][1]\n# ids = pred_test_2[1][2]# sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/train/images/007a18eb4e09.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:40.479127Z","iopub.execute_input":"2023-06-02T07:02:40.479654Z","iopub.status.idle":"2023-06-02T07:02:40.539315Z","shell.execute_reply.started":"2023-06-02T07:02:40.479621Z","shell.execute_reply":"2023-06-02T07:02:40.538296Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # print(sh)\n# print(sh.shape)\n# implt = plt.imshow(sh)\n# plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:40.540611Z","iopub.execute_input":"2023-06-02T07:02:40.541199Z","iopub.status.idle":"2023-06-02T07:02:40.546416Z","shell.execute_reply.started":"2023-06-02T07:02:40.541165Z","shell.execute_reply":"2023-06-02T07:02:40.545246Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dls_2.show_batch(max_n=3)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:40.547717Z","iopub.execute_input":"2023-06-02T07:02:40.548359Z","iopub.status.idle":"2023-06-02T07:02:41.349888Z","shell.execute_reply.started":"2023-06-02T07:02:40.548313Z","shell.execute_reply":"2023-06-02T07:02:41.348995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# predict = vision_learner(dls_2, resnet34, metrics=error_rate)\n# predict.fine_tune(1)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.351303Z","iopub.execute_input":"2023-06-02T07:02:41.352291Z","iopub.status.idle":"2023-06-02T07:02:41.356651Z","shell.execute_reply.started":"2023-06-02T07:02:41.352254Z","shell.execute_reply":"2023-06-02T07:02:41.355548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import torch\nimport fastai","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.358142Z","iopub.execute_input":"2023-06-02T07:02:41.358604Z","iopub.status.idle":"2023-06-02T07:02:41.367431Z","shell.execute_reply.started":"2023-06-02T07:02:41.358569Z","shell.execute_reply":"2023-06-02T07:02:41.366466Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(torch.__version__)\nprint(fastai.__version__)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.368831Z","iopub.execute_input":"2023-06-02T07:02:41.369341Z","iopub.status.idle":"2023-06-02T07:02:41.378663Z","shell.execute_reply.started":"2023-06-02T07:02:41.369309Z","shell.execute_reply":"2023-06-02T07:02:41.377472Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !pip install torch==<version_number>\n# !pip install fastai==<version_number>","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.380338Z","iopub.execute_input":"2023-06-02T07:02:41.380716Z","iopub.status.idle":"2023-06-02T07:02:41.388156Z","shell.execute_reply.started":"2023-06-02T07:02:41.380685Z","shell.execute_reply":"2023-06-02T07:02:41.387129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from fastai.vision.all import *","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.389368Z","iopub.execute_input":"2023-06-02T07:02:41.389918Z","iopub.status.idle":"2023-06-02T07:02:41.398868Z","shell.execute_reply.started":"2023-06-02T07:02:41.389884Z","shell.execute_reply":"2023-06-02T07:02:41.397931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from fastai.vision.all import *\n\n# # Load the test image\n# test_image_path = \"/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg\"\n# test_image = PIL.Image.open(test_image_path)\n\n# # Define the transformation pipeline\n# test_tfms = setup_aug_tfms([Resize(224), ToTensor()])\n\n# # Apply transformations to the test image\n# test_image_tensor = Pipeline(test_tfms)(test_image)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.400122Z","iopub.execute_input":"2023-06-02T07:02:41.400571Z","iopub.status.idle":"2023-06-02T07:02:41.408911Z","shell.execute_reply.started":"2023-06-02T07:02:41.400538Z","shell.execute_reply":"2023-06-02T07:02:41.407966Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# chart_type, y_axis, chart_id = predict.predict(test_image_tensor)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.410303Z","iopub.execute_input":"2023-06-02T07:02:41.410657Z","iopub.status.idle":"2023-06-02T07:02:41.418896Z","shell.execute_reply.started":"2023-06-02T07:02:41.41062Z","shell.execute_reply":"2023-06-02T07:02:41.417803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# chart_type = str(chart_type)\n# x_axis = str(x_axis)\n# y_axis = str(y_axis)\n# chart_id = str(chart_id)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.419959Z","iopub.execute_input":"2023-06-02T07:02:41.420251Z","iopub.status.idle":"2023-06-02T07:02:41.43025Z","shell.execute_reply.started":"2023-06-02T07:02:41.420215Z","shell.execute_reply":"2023-06-02T07:02:41.429163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print(\"Chart Type:\", chart_type)\n# print(\"X-Axis:\", x_axis)\n# print(\"Y-Axis:\", y_axis)\n# # print(\"Chart ID:\", chart_id)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.431835Z","iopub.execute_input":"2023-06-02T07:02:41.432183Z","iopub.status.idle":"2023-06-02T07:02:41.439987Z","shell.execute_reply.started":"2023-06-02T07:02:41.43215Z","shell.execute_reply":"2023-06-02T07:02:41.438944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# from fastai.vision.all import *\n\n# # Load the test image\n# test_image_path = \"/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg\"\n# test_image = PIL.Image.open(test_image_path)\n\n# # Define the transformation pipeline\n# test_tfms = setup_aug_tfms([Resize(224), ToTensor()])\n\n# # Apply transformations to the test image\n# test_image_tensor = test_tfms(test_image)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.4413Z","iopub.execute_input":"2023-06-02T07:02:41.442377Z","iopub.status.idle":"2023-06-02T07:02:41.450037Z","shell.execute_reply.started":"2023-06-02T07:02:41.442345Z","shell.execute_reply":"2023-06-02T07:02:41.449094Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_image_path = \"/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg\"\n# test_image = PIL.Image.open(test_image_path)\n# test_dl = dls.test_dl([test_image])\n# test_image_tensor = test_dl.one_batch()[0]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.451486Z","iopub.execute_input":"2023-06-02T07:02:41.452521Z","iopub.status.idle":"2023-06-02T07:02:41.459485Z","shell.execute_reply.started":"2023-06-02T07:02:41.45249Z","shell.execute_reply":"2023-06-02T07:02:41.458453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_image_path = \"/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg\"\n# test_image = PIL.Image.open(test_image_path)\n# test_image_tensor = dls.test_dl([test_image])[0][0]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.460838Z","iopub.execute_input":"2023-06-02T07:02:41.461667Z","iopub.status.idle":"2023-06-02T07:02:41.47212Z","shell.execute_reply.started":"2023-06-02T07:02:41.461635Z","shell.execute_reply":"2023-06-02T07:02:41.471215Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# learn = load_learner(r\"/kaggle/input/benetech-making-graphs-accessible/test\")\n# learn = load_learner(\"/kaggle/input/benetech-making-graphs-accessible/model.pkl\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.473614Z","iopub.execute_input":"2023-06-02T07:02:41.47428Z","iopub.status.idle":"2023-06-02T07:02:41.483236Z","shell.execute_reply.started":"2023-06-02T07:02:41.474247Z","shell.execute_reply":"2023-06-02T07:02:41.482267Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_images = []\n# for image_path in test.glob(\"*.jpg\"):\n#     img = PIL.Image.open(image_path)\n#     test_images.append(img)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.484921Z","iopub.execute_input":"2023-06-02T07:02:41.485286Z","iopub.status.idle":"2023-06-02T07:02:41.491925Z","shell.execute_reply.started":"2023-06-02T07:02:41.485255Z","shell.execute_reply":"2023-06-02T07:02:41.491075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# predictions = []\n# for img in test_images:\n#     pred = learn.predict(img)\n#     predictions.append(pred)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.493434Z","iopub.execute_input":"2023-06-02T07:02:41.493764Z","iopub.status.idle":"2023-06-02T07:02:41.502468Z","shell.execute_reply.started":"2023-06-02T07:02:41.493733Z","shell.execute_reply":"2023-06-02T07:02:41.50153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pred_test_2 = predict.predict('/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg')\n# print(pred_test_2)\n# sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/train/images/007a18eb4e09.jpg')\n# # print(sh)\n# print(sh.shape)\n# implt = plt.imshow(sh)\n# plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.503672Z","iopub.execute_input":"2023-06-02T07:02:41.504547Z","iopub.status.idle":"2023-06-02T07:02:41.511845Z","shell.execute_reply.started":"2023-06-02T07:02:41.504512Z","shell.execute_reply":"2023-06-02T07:02:41.510781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# def extract_axis_values(annotation):\n#     x_values = annotation['xy_axes']['x_axis']['values']\n#     y_values = annotation['xy_axes']['y_axis']['values']\n#     return x_values, y_values\n\n# axis_values_dict = {}\n# for image_id, annotation in dict_.items():\n#     x_values, y_values = extract_axis_values(annotation)\n#     axis_values_dict[image_id] = {\n#         'x_values': x_values,\n#         'y_values': y_values\n#     }","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.513112Z","iopub.execute_input":"2023-06-02T07:02:41.513886Z","iopub.status.idle":"2023-06-02T07:02:41.522327Z","shell.execute_reply.started":"2023-06-02T07:02:41.513854Z","shell.execute_reply":"2023-06-02T07:02:41.521295Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# data_show['x_values'] = data_show['index'].map(lambda x: axis_values_dict[x]['x_values'])\n# data_show['y_values'] = data_show['index'].map(lambda x: axis_values_dict[x]['y_values'])","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.523555Z","iopub.execute_input":"2023-06-02T07:02:41.524467Z","iopub.status.idle":"2023-06-02T07:02:41.532707Z","shell.execute_reply.started":"2023-06-02T07:02:41.524432Z","shell.execute_reply":"2023-06-02T07:02:41.531864Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# image_ids","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.54831Z","iopub.execute_input":"2023-06-02T07:02:41.548918Z","iopub.status.idle":"2023-06-02T07:02:41.552631Z","shell.execute_reply.started":"2023-06-02T07:02:41.548894Z","shell.execute_reply":"2023-06-02T07:02:41.551677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# test_data = (r\"/kaggle/input/benetech-making-graphs-accessible/test/images\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.554035Z","iopub.execute_input":"2023-06-02T07:02:41.554739Z","iopub.status.idle":"2023-06-02T07:02:41.562292Z","shell.execute_reply.started":"2023-06-02T07:02:41.554707Z","shell.execute_reply":"2023-06-02T07:02:41.56137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show = ('/kaggle/input/benetech-making-graphs-accessible/test/images'+test_data[2])\n# show","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.565638Z","iopub.execute_input":"2023-06-02T07:02:41.566161Z","iopub.status.idle":"2023-06-02T07:02:41.571673Z","shell.execute_reply.started":"2023-06-02T07:02:41.566135Z","shell.execute_reply":"2023-06-02T07:02:41.570709Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pred_test_1 = predict.predict('/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg')\n# print(pred_test_1)\n# sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/train/images/000b92c3b098.jpg')\n# # print(sh)\n# print(sh.shape)\n# implt = plt.imshow(sh)\n# plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.574177Z","iopub.execute_input":"2023-06-02T07:02:41.574557Z","iopub.status.idle":"2023-06-02T07:02:41.580773Z","shell.execute_reply.started":"2023-06-02T07:02:41.574524Z","shell.execute_reply":"2023-06-02T07:02:41.579792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.581762Z","iopub.execute_input":"2023-06-02T07:02:41.583263Z","iopub.status.idle":"2023-06-02T07:02:41.593546Z","shell.execute_reply.started":"2023-06-02T07:02:41.583231Z","shell.execute_reply":"2023-06-02T07:02:41.592595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pred_test_2 = predict.predict('/kaggle/input/benetech-making-graphs-accessible/test/images/007a18eb4e09.jpg')\n# print(pred_test_2)\n# sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/train/images/007a18eb4e09.jpg')\n# # print(sh)\n# print(sh.shape)\n# implt = plt.imshow(sh)\n# plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.596216Z","iopub.execute_input":"2023-06-02T07:02:41.596948Z","iopub.status.idle":"2023-06-02T07:02:41.604838Z","shell.execute_reply.started":"2023-06-02T07:02:41.596915Z","shell.execute_reply":"2023-06-02T07:02:41.603249Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pred_test_3 = predict.predict('/kaggle/input/benetech-making-graphs-accessible/test/images/00dcf883a459.jpg')\n# print(pred_test_3)\n# sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/train/images/00dcf883a459.jpg')\n# # print(sh)\n# print(sh.shape)\n# implt = plt.imshow(sh)\n# plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.6061Z","iopub.execute_input":"2023-06-02T07:02:41.606971Z","iopub.status.idle":"2023-06-02T07:02:41.614995Z","shell.execute_reply.started":"2023-06-02T07:02:41.606938Z","shell.execute_reply":"2023-06-02T07:02:41.614251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pred_test_4 = predict.predict('/kaggle/input/benetech-making-graphs-accessible/test/images/00f5404753cf.jpg')\n# print(pred_test_4)\n# sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/train/images/00f5404753cf.jpg')\n# # print(sh)\n# print(sh.shape)\n# implt = plt.imshow(sh)\n# plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.616352Z","iopub.execute_input":"2023-06-02T07:02:41.617129Z","iopub.status.idle":"2023-06-02T07:02:41.625207Z","shell.execute_reply.started":"2023-06-02T07:02:41.617096Z","shell.execute_reply":"2023-06-02T07:02:41.624308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pred_test_5 = predict.predict('/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg')\n# sh = cv2.imread(r'/kaggle/input/benetech-making-graphs-accessible/train/images/01b45b831589.jpg')\n# # print(sh)\n# print(sh.shape)\n# implt = plt.imshow(sh)\n# plt.show()\n# print(pred_test_5)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.626425Z","iopub.execute_input":"2023-06-02T07:02:41.627323Z","iopub.status.idle":"2023-06-02T07:02:41.635508Z","shell.execute_reply.started":"2023-06-02T07:02:41.627291Z","shell.execute_reply":"2023-06-02T07:02:41.634534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show = os.listdir('/kaggle/input/benetech-making-graphs-accessible/test/images')","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.636674Z","iopub.execute_input":"2023-06-02T07:02:41.637545Z","iopub.status.idle":"2023-06-02T07:02:41.649618Z","shell.execute_reply.started":"2023-06-02T07:02:41.637511Z","shell.execute_reply":"2023-06-02T07:02:41.64767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for i in range(5):\n#         pred_test_show = predict.predict('/kaggle/input/benetech-making-graphs-accessible/test/images/'+show[i])[0]\n#         print(pred_test_show)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.651599Z","iopub.execute_input":"2023-06-02T07:02:41.652468Z","iopub.status.idle":"2023-06-02T07:02:41.661494Z","shell.execute_reply.started":"2023-06-02T07:02:41.652433Z","shell.execute_reply":"2023-06-02T07:02:41.658185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Iterate over the DataFrame rows\n# for idx, row in d_f_data.iterrows():\n#     # Get the image ID\n#     image_id = idx\n    \n#     # Get the chart type\n#     chart_type = row['chart_type']\n    \n#     # Load the corresponding annotation JSON file\n#     annotation_file = annotations / (image_id + '.json')\n#     annotation_data = json.load(open(annotation_file))\n    \n#     # Extract x-axis and y-axis values based on the chart type\n#     if chart_type == 'vertical_bar' or chart_type == 'horizontal_bar':\n#         x_values = annotation_data['xy_axes']['x-axis']['values']\n#         y_values = annotation_data['xy_axes']['y-axis']['values']\n#     elif chart_type == 'line_chart' or chart_type == 'scatter_plot':\n#         x_values = annotation_data['data_series'][0]['x']\n#         y_values = annotation_data['data_series'][0]['y']\n#     elif chart_type == 'dot_plot':\n#         x_values = annotation_data['xy_axes']['x-axis']['values']\n#         y_values = annotation_data['data_series'][0]['y']\n#     else:\n#         x_values = None\n#         y_values = None\n    \n#     # Print the image ID, chart type, and x-axis/y-axis values\n#     print(f\"Image ID: {image_id}\")\n#     print(f\"Chart Type: {chart_type}\")\n#     print(f\"X-axis values: {x_values}\")\n#     print(f\"Y-axis values: {y_values}\")\n#     print(\"-----------------------\")\n","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.663998Z","iopub.execute_input":"2023-06-02T07:02:41.664955Z","iopub.status.idle":"2023-06-02T07:02:41.670608Z","shell.execute_reply.started":"2023-06-02T07:02:41.664922Z","shell.execute_reply":"2023-06-02T07:02:41.669706Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Iterate over the DataFrame rows\n# for idx, row in d_f_data.iterrows():\n#     # Get the image ID\n#     image_id = idx\n    \n#     # Get the chart type\n#     chart_type = row['chart_type']\n    \n#     # Load the corresponding annotation JSON file\n#     annotation_file = annotations / (image_id + '.json')\n    \n#     try:\n#         annotation_data = json.load(open(annotation_file))\n        \n#         # Extract x-axis and y-axis values based on the chart type\n#         if chart_type == 'vertical_bar' or chart_type == 'horizontal_bar':\n#             # Modify this section based on the JSON structure\n#             # Example assumes the x-axis and y-axis values are directly accessible in the JSON\n#             x_values = annotation_data['x-axis-values']\n#             y_values = annotation_data['y-axis-values']\n#         elif chart_type == 'line_chart' or chart_type == 'scatter_plot':\n#             # Modify this section based on the JSON structure\n#             # Example assumes the x-axis and y-axis values are within the 'data-series' key\n#             x_values = annotation_data['data_series'][0]['x']\n#             y_values = annotation_data['data_series'][0]['y']\n#         elif chart_type == 'dot_plot':\n#             # Modify this section based on the JSON structure\n#             # Example assumes the x-axis values are accessible and y-axis values are within the 'data-series' key\n#             x_values = annotation_data['x-axis-values']\n#             y_values = annotation_data['data_series'][0]['y']\n#         else:\n#             x_values = None\n#             y_values = None\n        \n#         # Print the image ID, chart type, and x-axis/y-axis values\n#         print(f\"Image ID: {image_id}\")\n#         print(f\"Chart Type: {chart_type}\")\n#         demo_sub = pd.DataFrame(columns=[\"ids\", \"chart_type\"])\n#         print(f\"X-axis values: {x_values}\")\n#         print(f\"Y-axis values: {y_values}\")\n#         print(\"-----------------------\")\n    \n        \n#     except FileNotFoundError:\n#         print(f\"Annotation file not found for image ID: {image_id}\")\n#         print(\"-----------------------\")\n","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.67211Z","iopub.execute_input":"2023-06-02T07:02:41.672658Z","iopub.status.idle":"2023-06-02T07:02:41.68332Z","shell.execute_reply.started":"2023-06-02T07:02:41.672626Z","shell.execute_reply":"2023-06-02T07:02:41.68231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\n# Create an empty DataFrame\ndemo_sub = pd.DataFrame(columns=[\"ids\", \"chart_type\"])\n\n# Iterate over the DataFrame rows\nfor idx, row in d_f_data.iterrows():\n    # Get the image ID\n    image_id = idx\n    \n    # Get the chart type\n    chart_type = row['chart_type']\n    \n    # Load the corresponding annotation JSON file\n    annotation_file = annotations / (image_id + '.json')\n    \n    try:\n        annotation_data = json.load(open(annotation_file))\n        \n        # Extract x-axis and y-axis values based on the chart type\n        if chart_type == 'vertical_bar' or chart_type == 'horizontal_bar':\n            # Modify this section based on the JSON structure\n            # Example assumes the x-axis and y-axis values are directly accessible in the JSON\n            x_values = annotation_data['x-axis']['ticks']\n            y_values = annotation_data['y-axis']['ticks']\n        elif chart_type == 'line_chart' or chart_type == 'scatter_plot':\n            # Modify this section based on the JSON structure\n            # Example assumes the x-axis and y-axis values are within the 'data-series' key\n            x_values = annotation_data['data_series'][0]['x']\n            y_values = annotation_data['data_series'][0]['y']\n        elif chart_type == 'dot_plot':\n            # Modify this section based on the JSON structure\n            # Example assumes the x-axis values are accessible and y-axis values are within the 'data-series' key\n            x_values = annotation_data['x']\n            y_values = annotation_data['data_series'][0]['y']\n        else:\n            x_values = None\n            y_values = None\n        \n        # Add a new row to the DataFrame\n        demo_sub = demo_sub.append({\"ids\": image_id, \"chart_type\": chart_type}, ignore_index=True)\n        \n        # Print the image ID, chart type, and x-axis/y-axis values\n        print(f\"Image ID: {image_id}\")\n        print(f\"Chart Type: {chart_type}\")\n        print(f\"X-axis values: {x_values}\")\n        print(f\"Y-axis values: {y_values}\")\n        print(\"-----------------------\")\n    \n    except FileNotFoundError:\n        print(f\"Annotation file not found for image ID: {image_id}\")\n        print(\"-----------------------\")\n","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:41.686469Z","iopub.execute_input":"2023-06-02T07:02:41.686742Z","iopub.status.idle":"2023-06-02T07:02:44.036743Z","shell.execute_reply.started":"2023-06-02T07:02:41.686719Z","shell.execute_reply":"2023-06-02T07:02:44.035392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"demo_sub","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.038207Z","iopub.status.idle":"2023-06-02T07:02:44.038709Z","shell.execute_reply.started":"2023-06-02T07:02:44.038465Z","shell.execute_reply":"2023-06-02T07:02:44.038488Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import PIL\n# import os","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.040418Z","iopub.status.idle":"2023-06-02T07:02:44.040889Z","shell.execute_reply.started":"2023-06-02T07:02:44.040651Z","shell.execute_reply":"2023-06-02T07:02:44.040673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# predict = vision_learner(dls_2, resnet34, metrics=error_rate)\n# predict.fine_tune(1)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.042517Z","iopub.status.idle":"2023-06-02T07:02:44.042984Z","shell.execute_reply.started":"2023-06-02T07:02:44.042741Z","shell.execute_reply":"2023-06-02T07:02:44.042763Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import pandas as pd\n# import json\n# import torch\n# from torchvision import transforms\n# # from your_model_module import YourModelClass\n\n# # Load the trained model\n# # model = YourModelClass()\n# # model.load_state_dict(torch.load('your_model_weights.pth'))\n# # model.eval()\n\n# # Define transformations for image preprocessing\n# transform = transforms.Compose([\n#     transforms.Resize((224, 224)),  # Adjust the size as required by your model\n#     transforms.ToTensor(),\n#     transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])  # Adjust normalization parameters\n# ])\n\n# # Create an empty DataFrame to store predictions\n# predictions = pd.DataFrame(columns=[\"ids\", \"chart_type\", \"x_values\", \"y_values\"])\n\n# # Load the test images\n# directory = '/kaggle/input/benetech-making-graphs-accessible/test/images'\n# image_paths = os.listdir(directory)\n\n# test_image_paths = [os.path.join(directory, filename) for filename in image_paths]\n# print(test_image_paths[0])\n\n# for image_path in test_image_paths:\n#     # Load and preprocess the test image\n#     image = PIL.Image.open(image_path)\n#     image_tensor = transform(image).unsqueeze(0)  # Add an extra dimension for batch size if using a batched model\n\n#     # Perform prediction\n#     with torch.no_grad():\n#         output = predict.predict(image_tensor)\n\n#     # Process the prediction output and extract the relevant values\n#     ids = output['ids']\n#     chart_type = output['chart_type']\n#     x_values = output['x_values']\n#     y_values = output['y_values']\n\n#     # Add the predictions to the DataFrame\n#     predictions = predictions.append({\n#         \"ids\": ids,\n#         \"chart_type\": chart_type,\n#         \"x_values\": x_values,\n#         \"y_values\": y_values\n#     }, ignore_index=True)\n\n# # Print the predictions\n# print(predictions)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.044782Z","iopub.status.idle":"2023-06-02T07:02:44.045266Z","shell.execute_reply.started":"2023-06-02T07:02:44.045011Z","shell.execute_reply":"2023-06-02T07:02:44.045033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pip install jpype","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.046683Z","iopub.status.idle":"2023-06-02T07:02:44.047594Z","shell.execute_reply.started":"2023-06-02T07:02:44.047342Z","shell.execute_reply":"2023-06-02T07:02:44.047368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !sudo apt install tesseract-ocr","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.049219Z","iopub.status.idle":"2023-06-02T07:02:44.049699Z","shell.execute_reply.started":"2023-06-02T07:02:44.049461Z","shell.execute_reply":"2023-06-02T07:02:44.049483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !sudo apt install libtesseract-dev ","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.051338Z","iopub.status.idle":"2023-06-02T07:02:44.051813Z","shell.execute_reply.started":"2023-06-02T07:02:44.051566Z","shell.execute_reply":"2023-06-02T07:02:44.051589Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !pip install tesseract","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.05329Z","iopub.status.idle":"2023-06-02T07:02:44.05432Z","shell.execute_reply.started":"2023-06-02T07:02:44.054042Z","shell.execute_reply":"2023-06-02T07:02:44.054081Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !pip install tesseract-ocr","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.055722Z","iopub.status.idle":"2023-06-02T07:02:44.056209Z","shell.execute_reply.started":"2023-06-02T07:02:44.05595Z","shell.execute_reply":"2023-06-02T07:02:44.055973Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !tesseract","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.059558Z","iopub.status.idle":"2023-06-02T07:02:44.060027Z","shell.execute_reply.started":"2023-06-02T07:02:44.059787Z","shell.execute_reply":"2023-06-02T07:02:44.059808Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import cv2\n# import numpy as np\n# import pandas as pd\n# import matplotlib.pyplot as plt\n# import csv\n\n# import os\n# from pathlib import Path\n# import subprocess","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.061851Z","iopub.status.idle":"2023-06-02T07:02:44.062346Z","shell.execute_reply.started":"2023-06-02T07:02:44.062095Z","shell.execute_reply":"2023-06-02T07:02:44.062117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import  jpype     \n# import  asposecells     \n# jpype.startJVM() \n# from asposecells.api import Workbook\n# workbook = Workbook(pred_test_5)\n# workbook.save(\"Output.xlsx\")\n# jpype.shutdownJVM()","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.063744Z","iopub.status.idle":"2023-06-02T07:02:44.064567Z","shell.execute_reply.started":"2023-06-02T07:02:44.064309Z","shell.execute_reply":"2023-06-02T07:02:44.064341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pip install tesseract","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.066157Z","iopub.status.idle":"2023-06-02T07:02:44.066622Z","shell.execute_reply.started":"2023-06-02T07:02:44.066386Z","shell.execute_reply":"2023-06-02T07:02:44.066409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pip install pytesseract","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.068329Z","iopub.status.idle":"2023-06-02T07:02:44.068789Z","shell.execute_reply.started":"2023-06-02T07:02:44.068553Z","shell.execute_reply":"2023-06-02T07:02:44.068576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import pytesseract","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.070386Z","iopub.status.idle":"2023-06-02T07:02:44.070845Z","shell.execute_reply.started":"2023-06-02T07:02:44.070609Z","shell.execute_reply":"2023-06-02T07:02:44.07063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# for i in range(5):\n#         pred_test_show = pytesseract(PIL.Image.open((r'/kaggle/input/benetech-making-graphs-accessible/test/images'+show[i])[0]))\n#         print(pred_test_show)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.072305Z","iopub.status.idle":"2023-06-02T07:02:44.073323Z","shell.execute_reply.started":"2023-06-02T07:02:44.073037Z","shell.execute_reply":"2023-06-02T07:02:44.073077Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# pip install easyocr","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.074649Z","iopub.status.idle":"2023-06-02T07:02:44.07513Z","shell.execute_reply.started":"2023-06-02T07:02:44.074871Z","shell.execute_reply":"2023-06-02T07:02:44.074899Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import easyocr","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.07853Z","iopub.status.idle":"2023-06-02T07:02:44.078989Z","shell.execute_reply.started":"2023-06-02T07:02:44.078755Z","shell.execute_reply":"2023-06-02T07:02:44.078778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# myconfig = r'--psm 6 oem 3'","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.080575Z","iopub.status.idle":"2023-06-02T07:02:44.081036Z","shell.execute_reply.started":"2023-06-02T07:02:44.080799Z","shell.execute_reply":"2023-06-02T07:02:44.08082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show_vertical_axis = pytesseract.image_to_string(PIL.Image.open('/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg'), config=myconfig)\n# show_vertical_axis","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.082663Z","iopub.status.idle":"2023-06-02T07:02:44.083144Z","shell.execute_reply.started":"2023-06-02T07:02:44.08289Z","shell.execute_reply":"2023-06-02T07:02:44.082912Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show = pytesseract.image_to_string(PIL.Image.open('/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg'), config=myconfig)","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.084723Z","iopub.status.idle":"2023-06-02T07:02:44.085207Z","shell.execute_reply.started":"2023-06-02T07:02:44.084945Z","shell.execute_reply":"2023-06-02T07:02:44.084968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# image_1 = '/kaggle/input/benetech-making-graphs-accessible/test/images/01b45b831589.jpg'\n# image_1 = cv2.imread(image_1)\n\n# # Perform OCR using Tesseract\n# custom_config = r'--oem 3 --psm 6'  # Tesseract configuration for better accuracy\n# ocr_output = pytesseract.image_to_string(image_1, config=custom_config)\n# # Extract text and numbers from OCR output\n# text = \"\"\n# numbers = []\n# lines = ocr_output.split('\\n')\n# for line in lines:\n#     line = line.strip()\n#     if line:\n#         if line.isdigit():  # Check if the line contains only numbers\n#             numbers.append(int(line))\n#         else:\n#             text += line + \" \"\n# # Print the extracted text and numbers\n# print(\"Extracted Text:\", text)\n# print(\"Extracted Numbers:\", numbers)\n","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.086834Z","iopub.status.idle":"2023-06-02T07:02:44.087304Z","shell.execute_reply.started":"2023-06-02T07:02:44.087073Z","shell.execute_reply":"2023-06-02T07:02:44.087095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# show_line_axis = pytesseract.image_to_string(PIL.Image.open(r'/kaggle/input/benetech-making-graphs-accessible/test/images/000b92c3b098.jpg'), config=myconfig)\n# show_line_axis[25:36]","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.088905Z","iopub.status.idle":"2023-06-02T07:02:44.089394Z","shell.execute_reply.started":"2023-06-02T07:02:44.089144Z","shell.execute_reply":"2023-06-02T07:02:44.089167Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# # Assuming `annotation_data` is the dictionary containing the annotation entry\n# x_ticks = annotation_data['x-axis']['ticks']\n# y_ticks = annotation_data['y-axis']['ticks']\n\n# # Iterate over the x-axis ticks and print their coordinates\n# for tick in x_ticks:\n#     x = tick['tick_pt']['x']\n#     y = tick['tick_pt']['y']\n#     print(f\"x-coordinate: {x}, y-coordinate: {y}\")\n\n# # Iterate over the y-axis ticks and print their coordinates\n# for tick in y_ticks:\n#     x = tick['tick_pt']['x']\n#     y = tick['tick_pt']['y']\n#     print(f\"x-coordinate: {x}, y-coordinate: {y}\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.091023Z","iopub.status.idle":"2023-06-02T07:02:44.091511Z","shell.execute_reply.started":"2023-06-02T07:02:44.091265Z","shell.execute_reply":"2023-06-02T07:02:44.091287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import pandas as pd\n# import json\n\n# # Create an empty DataFrame\n# demo_sub = pd.DataFrame(columns=[\"ids\", \"chart_type\", \"x_values\", \"y_values\"])\n\n# # Iterate over the DataFrame rows\n# for idx, row in d_f_data.iterrows():\n#     # Get the image ID\n#     image_id = idx\n    \n#     # Get the chart type\n#     chart_type = row['chart_type']\n    \n#     # Load the corresponding annotation JSON file\n#     annotation_file = annotations / (image_id + '.json')\n    \n#     try:\n#         with open(annotation_file) as f:\n#             annotation_data = json.load(f)\n        \n#         # Extract x-axis and y-axis values based on the chart type\n#         if chart_type == 'vertical_bar' or chart_type == 'horizontal_bar':\n#             x_values = [tick['tick_pt']['x'] for tick in annotation_data['x-axis']['ticks']]\n#             y_values = [tick['tick_pt']['y'] for tick in annotation_data['y-axis']['ticks']]\n#         elif chart_type == 'line_chart' or chart_type == 'scatter_plot':\n#             x_values = annotation_data['data_series'][0]['x']\n#             y_values = annotation_data['data_series'][0]['y']\n#         elif chart_type == 'dot_plot':\n#             x_values = annotation_data['x']\n#             y_values = annotation_data['data_series'][0]['y']\n#         else:\n#             x_values = None\n#             y_values = None\n        \n#         # Add a new row to the DataFrame\n#         demo_sub = demo_sub.append({\n#             \"ids\": image_id,\n#             \"chart_type\": chart_type,\n#             \"x_values\": x_values,\n#             \"y_values\": y_values\n#         }, ignore_index=True)\n        \n#         # Print the image ID, chart type, and x-axis/y-axis values\n#         print(f\"Image ID: {image_id}\")\n#         print(f\"Chart Type: {chart_type}\")\n#         print(f\"X-axis values: {x_values}\")\n#         print(f\"Y-axis values: {y_values}\")\n#         print(\"-----------------------\")\n    \n#     except FileNotFoundError:\n#         print(f\"Annotation file not found for image ID: {image_id}\")\n#         print(\"-----------------------\")","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.093246Z","iopub.status.idle":"2023-06-02T07:02:44.093729Z","shell.execute_reply.started":"2023-06-02T07:02:44.093494Z","shell.execute_reply":"2023-06-02T07:02:44.093516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# import pandas as pd\n# import json\n\n# # Create an empty DataFrame\n# demo_sub = pd.DataFrame(columns=[\"ids\", \"chart_type\", \"x_values\", \"y_values\"])\n\n# # Iterate over the DataFrame rows\n# for idx, row in d_f_data.iterrows():\n#     # Get the image ID\n#     image_id = idx\n    \n#     # Get the chart type\n#     chart_type = row['chart_type']\n    \n#     # Load the corresponding annotation JSON file\n#     annotation_file = annotations / (image_id + '.json')\n    \n#     try:\n#         with open(annotation_file) as f:\n#             annotation_data = json.load(f)\n        \n#         # Extract x-axis and y-axis values based on the chart type\n#         if chart_type == 'vertical_bar' or chart_type == 'horizontal_bar':\n#             x_values = [tick['text'] for tick in annotation_data['text'] if tick['role'] == 'tick_label']\n#             y_values = []\n#             for data in annotation_data['visual-elements']['bars']:\n#                 if 'y' in data:\n#                     y_values.append(data['y'])\n#                 elif 'top_left' in data and 'bottom_right' in data:\n#                     y_values.append((data['top_left']['y'] + data['bottom_right']['y']) / 2)\n#         elif chart_type == 'line_chart' or chart_type == 'scatter_plot':\n#             data_series = annotation_data['data-series'][0]\n#             x_values = data_series['x']\n#             y_values = data_series['y']\n#         elif chart_type == 'dot_plot':\n#             x_values = [data['x'] for data in annotation_data['visual-elements']['dot points']]\n#             y_values = [data['y'] for data in annotation_data['visual-elements']['dot points']]\n#         else:\n#             x_values = None\n#             y_values = None\n        \n#         # Add a new row to the DataFrame\n#         demo_sub = demo_sub.append({\n#             \"ids\": image_id,\n#             \"chart_type\": chart_type,\n#             \"x_values\": x_values,\n#             \"y_values\": y_values\n#         }, ignore_index=True)\n        \n#         # Print the image ID, chart type, and x-axis/y-axis values\n#         print(f\"Image ID: {image_id}\")\n#         print(f\"Chart Type: {chart_type}\")\n#         print(f\"X-axis values: {x_values}\")\n#         print(f\"Y-axis values: {y_values}\")\n#         print(\"-----------------------\")\n    \n#     except FileNotFoundError:\n#         print(f\"Annotation file not found for image ID: {image_id}\")\n#         print(\"-----------------------\")\n","metadata":{"execution":{"iopub.status.busy":"2023-06-02T07:02:44.09541Z","iopub.status.idle":"2023-06-02T07:02:44.095869Z","shell.execute_reply.started":"2023-06-02T07:02:44.095632Z","shell.execute_reply":"2023-06-02T07:02:44.095654Z"},"trusted":true},"execution_count":null,"outputs":[]}]}