{"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":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-01T17:09:18.238766Z","iopub.execute_input":"2022-04-01T17:09:18.239067Z","iopub.status.idle":"2022-04-01T17:09:18.251663Z","shell.execute_reply.started":"2022-04-01T17:09:18.239034Z","shell.execute_reply":"2022-04-01T17:09:18.25074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"! pip install torchmetrics\nimport torch\nfrom torch import nn, optim\nfrom torchvision import datasets, transforms\nimport torchvision\nimport torchmetrics\n#from torchsummary import summary\nfrom matplotlib import pyplot as plt\nimport numpy as np \nimport pandas as pd\nfrom torch.utils.data import DataLoader,Dataset\nimport torch.nn.functional as F\nfrom sklearn.metrics import accuracy_score, confusion_matrix\n# if torch.cuda.is_available() is False:\n#     raise Exception(\"GPU device not found, runtime environment should be set to GPU\")\n# device = torch.device(\"cuda:0\")\n# print(f\"Using GPU device: {torch.cuda.get_device_name(torch.cuda.current_device())} - {device} \")","metadata":{"execution":{"iopub.status.busy":"2022-04-02T07:43:34.024484Z","iopub.execute_input":"2022-04-02T07:43:34.025104Z","iopub.status.idle":"2022-04-02T07:44:05.476202Z","shell.execute_reply.started":"2022-04-02T07:43:34.025009Z","shell.execute_reply":"2022-04-02T07:44:05.475506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# wresnet_model_1 = torchvision.models.wide_resnet101_2(pretrained=True, progress=True)\n# wresnet_model_1.fc=nn.Linear(wresnet_model_1.fc.in_features,10)","metadata":{"execution":{"iopub.status.busy":"2022-04-01T17:04:29.377394Z","iopub.execute_input":"2022-04-01T17:04:29.377664Z","iopub.status.idle":"2022-04-01T17:04:42.086094Z","shell.execute_reply.started":"2022-04-01T17:04:29.377635Z","shell.execute_reply":"2022-04-01T17:04:42.085277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"wresnet_model_1=torch.load('/kaggle/input/gnetmodel2/googlenet_model_2')\nwresnet_model_1.eval()","metadata":{"execution":{"iopub.status.busy":"2022-04-02T07:44:13.727975Z","iopub.execute_input":"2022-04-02T07:44:13.728831Z","iopub.status.idle":"2022-04-02T07:44:17.947213Z","shell.execute_reply.started":"2022-04-02T07:44:13.728782Z","shell.execute_reply":"2022-04-02T07:44:17.946363Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = pd.read_csv('/kaggle/input/Kannada-MNIST/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-02T07:44:29.038266Z","iopub.execute_input":"2022-04-02T07:44:29.038784Z","iopub.status.idle":"2022-04-02T07:44:29.402856Z","shell.execute_reply.started":"2022-04-02T07:44:29.038744Z","shell.execute_reply":"2022-04-02T07:44:29.402067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids, test_set = test_data.id, test_data.drop(['id'], axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T07:44:32.756495Z","iopub.execute_input":"2022-04-02T07:44:32.757195Z","iopub.status.idle":"2022-04-02T07:44:32.786607Z","shell.execute_reply.started":"2022-04-02T07:44:32.757154Z","shell.execute_reply":"2022-04-02T07:44:32.785874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class md3_test(Dataset):\n\n  def __init__(self,d):\n    x=d.values#.reshape(1,28,28)\n    \n    self.x_train=torch.tensor(x,dtype=torch.float32)\n\n  def __len__(self):\n    return len(self.x_train)\n  \n  def __getitem__(self,idx): \n    x=self.x_train[idx].reshape(28,28)\n    x.unsqueeze_(0)\n    x = x.repeat(3, 1, 1)\n    return x","metadata":{"execution":{"iopub.status.busy":"2022-04-02T07:44:35.188748Z","iopub.execute_input":"2022-04-02T07:44:35.18904Z","iopub.status.idle":"2022-04-02T07:44:35.194371Z","shell.execute_reply.started":"2022-04-02T07:44:35.189008Z","shell.execute_reply":"2022-04-02T07:44:35.193759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"md_test3=md3_test(test_set)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T07:44:44.338476Z","iopub.execute_input":"2022-04-02T07:44:44.338905Z","iopub.status.idle":"2022-04-02T07:44:44.352888Z","shell.execute_reply.started":"2022-04-02T07:44:44.338866Z","shell.execute_reply":"2022-04-02T07:44:44.352024Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dataloader=torch.utils.data.DataLoader(md_test3, batch_size = 128, num_workers = 2)\nsoftmax = nn.Softmax(dim = 1)","metadata":{"execution":{"iopub.status.busy":"2022-04-02T07:44:48.614253Z","iopub.execute_input":"2022-04-02T07:44:48.61478Z","iopub.status.idle":"2022-04-02T07:44:48.618768Z","shell.execute_reply.started":"2022-04-02T07:44:48.614747Z","shell.execute_reply":"2022-04-02T07:44:48.617962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test_dataloader.dataset[1].shape\npred_test=[]\nwresnet_model_1.eval()\n#[densenet201_model_1(x[0]) for x in val_data3.dataset]\nfor x in test_dataloader:\n    pred_test.append((softmax(wresnet_model_1(x)).to('cpu')).detach().numpy())\n    ","metadata":{"execution":{"iopub.status.busy":"2022-04-02T07:44:55.213776Z","iopub.execute_input":"2022-04-02T07:44:55.214467Z","iopub.status.idle":"2022-04-02T07:46:09.058224Z","shell.execute_reply.started":"2022-04-02T07:44:55.214429Z","shell.execute_reply":"2022-04-02T07:46:09.057121Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.Series([int(y.argmax()) for x in pred_test for y in x], index=ids, name='label').to_csv('/kaggle/working/submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-02T07:46:09.077733Z","iopub.execute_input":"2022-04-02T07:46:09.078027Z","iopub.status.idle":"2022-04-02T07:46:09.0913Z","shell.execute_reply.started":"2022-04-02T07:46:09.077988Z","shell.execute_reply":"2022-04-02T07:46:09.090343Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]}]}