{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":19989,"databundleVersionId":1160143,"sourceType":"competition"}],"dockerImageVersionId":30684,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nimport os\nfrom tqdm.auto import tqdm\nimport shutil as sh\nimport seaborn as sns\nfrom matplotlib import pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-04-13T04:52:26.813562Z","iopub.execute_input":"2024-04-13T04:52:26.814020Z","iopub.status.idle":"2024-04-13T04:52:26.820420Z","shell.execute_reply.started":"2024-04-13T04:52:26.813989Z","shell.execute_reply":"2024-04-13T04:52:26.819337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 读取数据查看数据集列名和数据类型","metadata":{}},{"cell_type":"code","source":"df=pd.read_csv('../input/global-wheat-detection/train.csv')\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-13T04:52:26.822229Z","iopub.execute_input":"2024-04-13T04:52:26.822556Z","iopub.status.idle":"2024-04-13T04:52:27.056374Z","shell.execute_reply.started":"2024-04-13T04:52:26.822529Z","shell.execute_reply":"2024-04-13T04:52:27.055300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df[['x','y','w','h']] = np.stack(df['bbox'].apply(lambda x: np.fromstring(x[1:-1], sep=','))).astype(np.float64)\ndf.drop(columns=['bbox'], inplace=True)\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2024-04-13T04:52:27.058043Z","iopub.execute_input":"2024-04-13T04:52:27.058504Z","iopub.status.idle":"2024-04-13T04:52:27.796911Z","shell.execute_reply.started":"2024-04-13T04:52:27.058464Z","shell.execute_reply":"2024-04-13T04:52:27.795740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 数据集的大小和维度","metadata":{}},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2024-04-13T04:52:35.923025Z","iopub.execute_input":"2024-04-13T04:52:35.924211Z","iopub.status.idle":"2024-04-13T04:52:35.930931Z","shell.execute_reply.started":"2024-04-13T04:52:35.924167Z","shell.execute_reply":"2024-04-13T04:52:35.929916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 查看图片的数量","metadata":{}},{"cell_type":"code","source":"df['image_id'].nunique()","metadata":{"execution":{"iopub.status.busy":"2024-04-13T04:52:39.083413Z","iopub.execute_input":"2024-04-13T04:52:39.084425Z","iopub.status.idle":"2024-04-13T04:52:39.106351Z","shell.execute_reply.started":"2024-04-13T04:52:39.084382Z","shell.execute_reply":"2024-04-13T04:52:39.105017Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 查看图片大小","metadata":{}},{"cell_type":"code","source":"df['width'].unique(), df['height'].unique()","metadata":{"execution":{"iopub.status.busy":"2024-04-13T04:52:46.390041Z","iopub.execute_input":"2024-04-13T04:52:46.390541Z","iopub.status.idle":"2024-04-13T04:52:46.400477Z","shell.execute_reply.started":"2024-04-13T04:52:46.390502Z","shell.execute_reply":"2024-04-13T04:52:46.399273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"counts = df['image_id'].value_counts()\nprint(f'number of boxes, range [{min(counts)}, {max(counts)}]')\nsns.displot(counts, kde=False)\nplt.xlabel('boxes')\nplt.ylabel('images')\nplt.title('boxes vs. images')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-13T04:53:29.245625Z","iopub.execute_input":"2024-04-13T04:53:29.246109Z","iopub.status.idle":"2024-04-13T04:53:29.600810Z","shell.execute_reply.started":"2024-04-13T04:53:29.246074Z","shell.execute_reply":"2024-04-13T04:53:29.599714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"一些图像可能包含更多的物体或更复杂的场景，因此可能需要更多的“框”来表示。这可能会影响模型的训练，因为模型可能需要不同的能力来处理不同复杂度的图像。","metadata":{}},{"cell_type":"markdown","source":"# 绘制图像","metadata":{}},{"cell_type":"code","source":"df['cx'] = df['x'] +df['w'] / 2\ndf['cy'] = df['y'] +df['h'] / 2\n#这两行代码计算了train_df中每个矩形框的中心坐标，以更容易地进行一些后续处理，比如计算边界框之间的距离或进行聚类等。\nax = plt.subplots(1, 3, figsize=(16, 4), tight_layout=True)[1].ravel()\n#这行代码创建了一个1行4列的图形布局，并设置了图形的大小为16x4英寸。tight_layout=True确保子图之间的间距是紧凑的。[1].ravel()用来提取子图数组并将其展平为一维数组\nax[0].set_title('x vs. y')\nax[0].set_xlim(0, 1024)\nax[0].set_ylim(0, 1024)\nax[1].set_title('cx vs. cy')\nax[1].set_xlim(0, 1024)\nax[1].set_ylim(0, 1024)\nax[2].set_title('area size')\nsns.histplot(data=df, x='x', y='y', ax=ax[0], bins=50, pmax=0.9)\nsns.histplot(data=df, x='cx', y='cy', ax=ax[1], bins=50, pmax=0.9)\nsns.histplot(df['w'] * df['h'], ax=ax[2], bins=50, kde=False)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-13T05:28:13.408951Z","iopub.execute_input":"2024-04-13T05:28:13.409401Z","iopub.status.idle":"2024-04-13T05:28:14.934842Z","shell.execute_reply.started":"2024-04-13T05:28:13.409368Z","shell.execute_reply":"2024-04-13T05:28:14.933609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"二维直方图的分布是均匀的，即各个颜色或密度级别在整个图表区域内大致相等\n无显著相关性：x 变量和 y 变量之间没有强烈的正相关或负相关关系\n独立变量：x 变量和 y 变量可能是独立的，即一个变量的变化不会显著影响另一个变量的变化\n随机分布：数据点可能只是随机分布在二维空间中，没有明确的模式或趋势\nhttps://yiyan.baidu.com/share/atCXs9NOU1","metadata":{}},{"cell_type":"markdown","source":"柱子很窄且间隔均匀，说明数据点相对集中","metadata":{}}]}