{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":66658,"databundleVersionId":7391548,"sourceType":"competition"}],"dockerImageVersionId":30627,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# 先知晓一下当前的目录地址\n!pwd","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:33:01.225909Z","iopub.execute_input":"2023-12-29T09:33:01.226332Z","iopub.status.idle":"2023-12-29T09:33:02.291155Z","shell.execute_reply.started":"2023-12-29T09:33:01.226296Z","shell.execute_reply":"2023-12-29T09:33:02.290073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 安装必要的程序包\n!pip install --upgrade lalsuite","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:33:02.603851Z","iopub.execute_input":"2023-12-29T09:33:02.604680Z","iopub.status.idle":"2023-12-29T09:33:41.837587Z","shell.execute_reply.started":"2023-12-29T09:33:02.604643Z","shell.execute_reply":"2023-12-29T09:33:41.836281Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":"2023-12-29T09:33:41.839746Z","iopub.execute_input":"2023-12-29T09:33:41.840148Z","iopub.status.idle":"2023-12-29T09:33:42.245753Z","shell.execute_reply.started":"2023-12-29T09:33:41.840094Z","shell.execute_reply":"2023-12-29T09:33:42.244729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# PyTorch深度学习框架\n\nPyTorch是一个开源的深度学习框架，由Facebook的人工智能研究团队开发。它提供了两个高级功能：\n\n1. 强大的GPU加速的张量计算（如NumPy）库。\n2. 包含自动微分系统的深度神经网络。\n\nPyTorch的设计哲学是“尽可能地保持用户对过程的控制，而不是隐藏复杂的细节”。\n\n这使得PyTorch在研究和开发新的深度学习模型时非常灵活，因为用户可以看到并控制模型的内部操作。","metadata":{"execution":{"iopub.status.busy":"2023-12-29T07:37:37.269572Z","iopub.execute_input":"2023-12-29T07:37:37.270255Z","iopub.status.idle":"2023-12-29T07:37:37.281594Z","shell.execute_reply.started":"2023-12-29T07:37:37.270223Z","shell.execute_reply":"2023-12-29T07:37:37.280337Z"}}},{"cell_type":"markdown","source":"- 这部分代码主要是引入所需要的库","metadata":{}},{"cell_type":"code","source":"# 加载我给同志们准备好的程序脚本\nimport sys\nsys.path.append('/kaggle/input/2023-gwdata-bootcamp')\n\nimport warnings\nwarnings.filterwarnings(\"ignore\", \"Wswiglal-redir-stdio\")","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:33:42.246966Z","iopub.execute_input":"2023-12-29T09:33:42.247392Z","iopub.status.idle":"2023-12-29T09:33:42.252680Z","shell.execute_reply.started":"2023-12-29T09:33:42.247350Z","shell.execute_reply":"2023-12-29T09:33:42.251754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 把脚本里的所有关联的程序包、类、函数都 load 一下\nfrom main import *\nfrom utils import *","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:33:42.254499Z","iopub.execute_input":"2023-12-29T09:33:42.254809Z","iopub.status.idle":"2023-12-29T09:33:46.386761Z","shell.execute_reply.started":"2023-12-29T09:33:42.254782Z","shell.execute_reply":"2023-12-29T09:33:46.385759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Train\n\n这段代码是一个使用PyTorch进行二分类任务的例子，任务是通过引力波数据（噪声+信号）来进行分类。\n\n首先，我们创建了一个数据生成器DatasetGenerator，它用于生成训练和测试数据集。每个epoch的样本数为100，信噪比为20。\n\n然后，我们使用PyTorch的DataLoader创建了训练和测试数据加载器，批处理大小为32，数据在每个epoch后都会被打乱。\n\n接着，我们加载了预训练的模型，如果没有预训练的模型，就会初始化一个新的模型。模型和损失历史的输出路径为./checkpoints_cnn/。\n\n然后，我们设置了优化器的参数，学习率为0.003，总的训练轮数为100，如果有预训练的模型，训练轮数会加上已经训练过的轮数。\n\n最后，我们调用train函数开始训练模型。训练过程中，模型会在每个epoch后在测试集上进行评估，并保存测试损失最小的模型。","metadata":{}},{"cell_type":"code","source":"# 初始化数据生成 class\nnsample_perepoch = 100  # 每个epoch的样本数\ndataset_train = DatasetGenerator(snr=20, nsample_perepoch=nsample_perepoch)  # 训练数据集\ndataset_test = DatasetGenerator(snr=20, nsample_perepoch=nsample_perepoch)  # 测试数据集\n\n# 创建一个DataLoader\ndata_loader = DataLoader(dataset_train, batch_size=32, shuffle=True,)  # 训练数据加载器\ntest_iter = DataLoader(dataset_test, batch_size=32, shuffle=True,)  # 测试数据加载器\n\ndevice = torch.device('cuda')  # 使用CUDA设备\n\n# 模型和损失历史的输出路径\ncheckpoint_dir = './checkpoints_cnn/'\n\n# 创建模型    \nnet, epoch, train_loss_history = load_model(checkpoint_dir)  # 加载模型\nnet.to(device);  # 将模型转移到设备上\n\n# 优化器参数\nlr = 0.003  # 学习率\ntotal_epochs = 100  # 总的训练轮数\ntotal_epochs += epoch  # 加上已经训练过的轮数\noutput_freq = 1  # 输出频率\n\n# 训练模型\ntrain(net, lr, nsample_perepoch, epoch, total_epochs,\n      dataset_train, data_loader, test_iter,\n      train_loss_history, checkpoint_dir, device, notebook=True)","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:35:44.276335Z","iopub.execute_input":"2023-12-29T09:35:44.277666Z","iopub.status.idle":"2023-12-29T09:42:30.088233Z","shell.execute_reply.started":"2023-12-29T09:35:44.277628Z","shell.execute_reply":"2023-12-29T09:42:30.086680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Evaluate\n\n这段代码定义了一个函数evaluate_gpu，用于在GPU上计算模型在数据集上的预测结果。\n\n首先，我们检查输入的模型net是否是nn.Module的实例。如果是，我们将模型设置为评估模式，并获取模型的设备。如果用户没有指定设备，我们将使用模型的第一个参数所在的设备。\n\n然后，我们定义了一个softmax函数，用于将模型的输出转换为概率。\n\n接着，我们创建了两个空列表y_hat_list和y_list，用于存储模型的预测结果和真实标签。\n\n然后，我们进入一个无需计算梯度的环境中，遍历数据加载器data_iter中的所有批次。对于每个批次，我们将数据和标签转移到设备上，并转换为适当的数据类型。然后，我们将数据通过模型进行前向传播，得到预测结果。\n\n接着，我们将预测结果通过softmax函数转换为概率，并将其转移到CPU上，然后转换为NumPy数组，取出正类的概率，并转换为列表。我们也将标签转移到CPU上，然后转换为NumPy数组，并转换为列表。\n\n最后，我们将预测结果和标签添加到y_hat_list和y_list中，并在遍历完所有批次后，将这两个列表转换为NumPy数组并返回。\n\n这个函数可以用于在训练过程中的每个epoch后，或者在训练完成后，评估模型在验证集或测试集上的性能。","metadata":{}},{"cell_type":"code","source":"# 加载必要的库\nimport warnings\nwarnings.filterwarnings(\"ignore\", \"Wswiglal-redir-stdio\")\nimport lal  # https://git.ligo.org/lscsoft/lalsuite/-/issues/300\nfrom main import *\nfrom utils import *\nfrom tqdm import tqdm\nfrom sklearn.metrics import roc_auc_score, roc_curve\n\ndef evaluate_gpu(net, data_iter, device=None):\n    \"\"\"使用GPU计算模型在数据集上的预测结果\"\"\"\n    if isinstance(net, nn.Module):\n        net.eval()  # 设置为评估模式\n        if not device:\n            device = next(iter(net.parameters())).device  # 获取设备信息\n    softmax = nn.Softmax(dim=-1)  # 定义softmax函数，dim=-1表示在最后一个维度上进行softmax运算\n    y_hat_list = []  # 初始化预测结果列表\n    y_list = []  # 初始化标签列表\n    with torch.no_grad():  # 不进行梯度计算\n        for X, y in data_iter:  # 遍历数据集\n            X = X.to(device).to(torch.float)  # 将数据转移到设备上并转换为浮点型\n            y = y.to(device).to(torch.long)  # 将标签转移到设备上并转换为长整型\n            y_hat = net(X)  # 使用模型进行预测\n\n            preds = softmax(y_hat).cpu().numpy()[:,1].tolist()  # 使用softmax函数处理预测结果，并转换为列表\n            labels = y.cpu().numpy().tolist()  # 将标签转换为列表\n\n            y_hat_list.extend(preds)  # 将预测结果添加到预测结果列表\n            y_list.extend(labels)  # 将标签添加到标签列表\n    return np.asarray(y_hat_list), np.asarray(y_list)  # 返回预测结果和标签的numpy数组```","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:53:39.576758Z","iopub.execute_input":"2023-12-29T09:53:39.577694Z","iopub.status.idle":"2023-12-29T09:53:39.737463Z","shell.execute_reply.started":"2023-12-29T09:53:39.577656Z","shell.execute_reply":"2023-12-29T09:53:39.736408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"下面这段代码是一个使用PyTorch进行二分类任务的例子，任务是通过引力波数据（噪声+信号）来进行分类。\n\n首先，我们创建了一个数据生成器DatasetGenerator，它用于生成测试数据集。每个epoch的样本数为1000，信噪比为20。\n\n然后，我们使用PyTorch的DataLoader创建了测试数据加载器，批处理大小为32，数据在每个epoch后都会被打乱。","metadata":{}},{"cell_type":"code","source":"nsample_perepoch = 1000 # num of injections\nsnr = 20  # 信噪比\n\ndataset_test = DatasetGenerator(snr=snr, nsample_perepoch=nsample_perepoch)\ndata_iter = DataLoader(dataset_test, batch_size=32, shuffle=True,)","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:53:40.680881Z","iopub.execute_input":"2023-12-29T09:53:40.681269Z","iopub.status.idle":"2023-12-29T09:54:09.570556Z","shell.execute_reply.started":"2023-12-29T09:53:40.681237Z","shell.execute_reply":"2023-12-29T09:54:09.569583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"接着，我们加载了预训练的模型。如果没有预训练的模型，就会初始化一个新的模型。模型和损失历史的输出路径为 `./checkpoints_cnn/`。","metadata":{}},{"cell_type":"code","source":"# load model\ndevice = torch.device('cuda')\n\n# Where we output our model and loss history\ncheckpoint_dir = './checkpoints_cnn/'\n\n# Creat model\nnet, epoch, train_loss_history = load_model(checkpoint_dir)\nnet.to(device);","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:54:13.673282Z","iopub.execute_input":"2023-12-29T09:54:13.674196Z","iopub.status.idle":"2023-12-29T09:54:13.733574Z","shell.execute_reply.started":"2023-12-29T09:54:13.674154Z","shell.execute_reply":"2023-12-29T09:54:13.732610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"然后，我们调用evaluate_gpu函数在测试集上进行预测，得到预测结果和真实标签。","metadata":{}},{"cell_type":"code","source":"y_hat_list, y_list = evaluate_gpu(net, data_iter, device)","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:54:15.687894Z","iopub.execute_input":"2023-12-29T09:54:15.688668Z","iopub.status.idle":"2023-12-29T09:54:16.019339Z","shell.execute_reply.started":"2023-12-29T09:54:15.688626Z","shell.execute_reply":"2023-12-29T09:54:16.018468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"接下来，我们使用roc_curve和roc_auc_score函数计算了ROC曲线和AUC值。","metadata":{}},{"cell_type":"code","source":"fpr, tpr, thresholds = roc_curve(y_list, y_hat_list)\nauc = roc_auc_score(y_list, y_hat_list)\nauc","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:54:16.964022Z","iopub.execute_input":"2023-12-29T09:54:16.964447Z","iopub.status.idle":"2023-12-29T09:54:16.982781Z","shell.execute_reply.started":"2023-12-29T09:54:16.964412Z","shell.execute_reply":"2023-12-29T09:54:16.981813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"然后，我们绘制了ROC曲线，并标出了阈值为0.5的点。","metadata":{}},{"cell_type":"code","source":"index = np.argmax(thresholds < 0.5)","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:54:18.689132Z","iopub.execute_input":"2023-12-29T09:54:18.690031Z","iopub.status.idle":"2023-12-29T09:54:18.694505Z","shell.execute_reply.started":"2023-12-29T09:54:18.689997Z","shell.execute_reply":"2023-12-29T09:54:18.693341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(fpr, tpr, color=\"deeppink\")\nplt.plot(*(np.linspace(0,1,100),)*2, 'k--', label='Luck (AUC=0.50)')\nplt.scatter(fpr[index], tpr[index], label=f'threshold={thresholds[index]:.2f}')\nplt.axis(\"square\")\n# plt.xscale('log')\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"ROC curves\")\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:54:21.279248Z","iopub.execute_input":"2023-12-29T09:54:21.279635Z","iopub.status.idle":"2023-12-29T09:54:21.684026Z","shell.execute_reply.started":"2023-12-29T09:54:21.279607Z","shell.execute_reply":"2023-12-29T09:54:21.683097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"最后，我们对不同的信噪比进行了测试，绘制了不同信噪比下的ROC曲线，并计算了AUC值。","metadata":{}},{"cell_type":"code","source":"from itertools import cycle\ncolors = cycle([\"deeppink\", \"aqua\", \"darkorange\", \"cornflowerblue\"])\n\nnsample_perepoch = 1000\nsnr_list = [5, 10, 15, 20]\nfor snr in tqdm(snr_list):\n    dataset_test = DatasetGenerator(snr=snr, nsample_perepoch=nsample_perepoch, verbose=False)\n    data_iter = DataLoader(dataset_test, batch_size=32, shuffle=True)\n    y_hat_list, y_list = evaluate_gpu(net, data_iter, device)\n\n    fpr, tpr, thresholds = roc_curve(y_list, y_hat_list)\n    auc = roc_auc_score(y_list, y_hat_list)\n    \n    plt.plot(fpr, tpr, color=next(colors), label=f'SNR={snr} (AUC={auc:.2f})')\nplt.plot(*(np.linspace(0,1,100),)*2, 'k--', label='Luck (AUC=0.50)')\n# plt.axis(\"square\")\nplt.xscale('log')\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"ROC curves\")\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:54:24.065544Z","iopub.execute_input":"2023-12-29T09:54:24.066425Z","iopub.status.idle":"2023-12-29T09:56:28.473432Z","shell.execute_reply.started":"2023-12-29T09:54:24.066388Z","shell.execute_reply":"2023-12-29T09:56:28.472401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"在最后一部分，我们计算了ROC曲线的误差，并绘制了带有误差的ROC曲线。\n\n这段代码展示了如何使用PyTorch进行二分类任务，并使用ROC曲线和AUC值进行模型评估。\n\n同时，也展示了如何对不同的信噪比进行测试，以及如何计算和绘制带有误差的ROC曲线。","metadata":{}},{"cell_type":"code","source":"from itertools import cycle\ncolors = cycle([\"deeppink\", \"aqua\", \"darkorange\", \"cornflowerblue\"])\n\ndef sigma(n, tp):\n    \"\"\"\n\n    :param tp:\n    :param n:\n    :return:\n    \"\"\"\n    return np.sqrt(tp*(1.-tp)/n)\n\nnsample_perepoch = 1000\nsnr_list = [2, 4, 6]\nfor snr in tqdm(snr_list):\n    dataset_test = DatasetGenerator(snr=snr, nsample_perepoch=nsample_perepoch, verbose=False)\n    data_iter = DataLoader(dataset_test, batch_size=32, shuffle=True)\n    y_hat_list, y_list = evaluate_gpu(net, data_iter, device)\n\n    fpr, tpr, _ = roc_curve(y_list, y_hat_list)\n    auc = roc_auc_score(y_list, y_hat_list)\n    \n    fpr_error = [sigma(len(y_list)/2., t) for t in fpr]\n    tpr_error = [sigma(len(y_list)/2., t) for t in tpr]\n    \n    color = next(colors)\n    plt.plot(fpr, tpr, color=color, label=f'SNR={snr} (AUC={auc:.2f})')\n    plt.fill_between(fpr, tpr+tpr_error, tpr-tpr_error, alpha=0.2, facecolor=color, zorder=0)\nplt.plot(*(np.linspace(0,1,100),)*2, 'k--', label='Luck (AUC=0.50)')\n# plt.axis(\"square\")\nplt.xscale('log')\nplt.yscale('log')\nplt.xlabel(\"False Positive Rate\")\nplt.ylabel(\"True Positive Rate\")\nplt.title(\"ROC curves\")\nplt.xlim(1e-4,1)\nplt.ylim(1e-4,1)\nplt.legend()\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:56:28.475134Z","iopub.execute_input":"2023-12-29T09:56:28.475447Z","iopub.status.idle":"2023-12-29T09:58:04.657130Z","shell.execute_reply.started":"2023-12-29T09:56:28.475418Z","shell.execute_reply":"2023-12-29T09:58:04.656031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submission","metadata":{}},{"cell_type":"code","source":"import lal\nimport _pickle as pickle\nfrom tqdm import tqdm\nfrom main import *\nfrom utils import *\n\ndef evaluate_submissoin_gpu(net, data_iter, device=None):\n    \"\"\"使用GPU计算模型在数据集上的预测结果\"\"\"\n    if isinstance(net, nn.Module):\n        net.eval()  # 设置为评估模式\n        if not device:\n            device = next(iter(net.parameters())).device  # 获取设备信息\n    softmax = nn.Softmax(dim=-1)  # 定义softmax函数，dim=-1表示在最后一个维度上进行softmax运算\n    y_hat_list = []  # 初始化预测结果列表\n    with torch.no_grad():  # 不进行梯度计算\n        for X in data_iter:  # 遍历数据集\n            X = X.to(device).to(torch.float)  # 将数据转移到设备上并转换为浮点型\n            y_hat = net(X)  # 使用模型进行预测\n            preds = softmax(y_hat).cpu().numpy()[:,1].tolist()  # 使用softmax函数处理预测结果，并转换为列表\n            y_hat_list.extend(preds)  # 将预测结果添加到预测结果列表\n    return y_hat_list","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:58:37.236309Z","iopub.execute_input":"2023-12-29T09:58:37.237182Z","iopub.status.idle":"2023-12-29T09:58:37.246087Z","shell.execute_reply.started":"2023-12-29T09:58:37.237133Z","shell.execute_reply":"2023-12-29T09:58:37.244915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_dataset = np.load('/kaggle/input/2023-gwdata-bootcamp/test.npy')\ntest_dataset.shape","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:58:38.480719Z","iopub.execute_input":"2023-12-29T09:58:38.481383Z","iopub.status.idle":"2023-12-29T09:58:41.516979Z","shell.execute_reply.started":"2023-12-29T09:58:38.481343Z","shell.execute_reply":"2023-12-29T09:58:41.515995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_loader = DataLoader(test_dataset, batch_size=32, shuffle=False,)","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:58:43.509706Z","iopub.execute_input":"2023-12-29T09:58:43.510459Z","iopub.status.idle":"2023-12-29T09:58:43.515125Z","shell.execute_reply.started":"2023-12-29T09:58:43.510423Z","shell.execute_reply":"2023-12-29T09:58:43.514079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# load model\ndevice = torch.device('cuda')\n\n# Where we output our model and loss history\ncheckpoint_dir = './checkpoints_cnn/'\n\n# Creat model\nnet, epoch, train_loss_history = load_model(checkpoint_dir)\nnet.to(device);","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:58:47.629161Z","iopub.execute_input":"2023-12-29T09:58:47.629577Z","iopub.status.idle":"2023-12-29T09:58:47.687819Z","shell.execute_reply.started":"2023-12-29T09:58:47.629544Z","shell.execute_reply":"2023-12-29T09:58:47.686946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results = evaluate_submissoin_gpu(net, data_loader, device)\nlen(results)","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:58:48.859769Z","iopub.execute_input":"2023-12-29T09:58:48.860611Z","iopub.status.idle":"2023-12-29T09:58:49.235918Z","shell.execute_reply.started":"2023-12-29T09:58:48.860572Z","shell.execute_reply":"2023-12-29T09:58:49.234913Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# results","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:58:50.767824Z","iopub.execute_input":"2023-12-29T09:58:50.768250Z","iopub.status.idle":"2023-12-29T09:58:50.773130Z","shell.execute_reply.started":"2023-12-29T09:58:50.768215Z","shell.execute_reply":"2023-12-29T09:58:50.771908Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\npd.DataFrame({'id': range(len(results)),\n              'target': results}, index=None).to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-12-29T09:58:53.741348Z","iopub.execute_input":"2023-12-29T09:58:53.741705Z","iopub.status.idle":"2023-12-29T09:58:53.762369Z","shell.execute_reply.started":"2023-12-29T09:58:53.741678Z","shell.execute_reply":"2023-12-29T09:58:53.761387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}