UESTC-BICS commited on
Commit
62b4c3f
·
1 Parent(s): ac9c669

Delete Load_Datasets_Example.ipynb

Browse files
Files changed (1) hide show
  1. Load_Datasets_Example.ipynb +0 -104
Load_Datasets_Example.ipynb DELETED
@@ -1,104 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 1,
6
- "metadata": {},
7
- "outputs": [],
8
- "source": [
9
- "import os\n",
10
- "import torch\n",
11
- "import numpy as np\n",
12
- "from torchvision import datasets"
13
- ]
14
- },
15
- {
16
- "cell_type": "code",
17
- "execution_count": null,
18
- "metadata": {},
19
- "outputs": [],
20
- "source": [
21
- "dataset_path = '/ssd/Datasets/I2E-ImageNet/'"
22
- ]
23
- },
24
- {
25
- "cell_type": "code",
26
- "execution_count": null,
27
- "metadata": {},
28
- "outputs": [],
29
- "source": [
30
- "class I2E_NpzFolder(datasets.DatasetFolder):\n",
31
- " def __init__(self, root, loader=None, extensions=['npz'], transform=None, target_transform=None, is_valid_file=None, allow_empty=False):\n",
32
- " super(I2E_NpzFolder, self).__init__(root, loader, extensions, transform, target_transform, is_valid_file, allow_empty)\n",
33
- "\n",
34
- " def __getitem__(self, index):\n",
35
- " path, target = self.samples[index]\n",
36
- " sample = torch.from_numpy(np.load(path)['arr_0']).float()\n",
37
- " if self.transform is not None:\n",
38
- " sample = self.transform(sample)\n",
39
- " if self.target_transform is not None:\n",
40
- " target = self.target_transform(target)\n",
41
- "\n",
42
- " return sample, target"
43
- ]
44
- },
45
- {
46
- "cell_type": "code",
47
- "execution_count": 4,
48
- "metadata": {},
49
- "outputs": [
50
- {
51
- "name": "stdout",
52
- "output_type": "stream",
53
- "text": [
54
- "len(train_dataset): 1281167, len(val_dataset): 50000\n"
55
- ]
56
- }
57
- ],
58
- "source": [
59
- "train_dataset = I2E_NpzFolder(root=os.path.join(dataset_path, 'train'))\n",
60
- "val_dataset = I2E_NpzFolder(root=os.path.join(dataset_path, 'val'))\n",
61
- "print(f'len(train_dataset): {len(train_dataset)}, len(val_dataset): {len(val_dataset)}')"
62
- ]
63
- },
64
- {
65
- "cell_type": "code",
66
- "execution_count": 5,
67
- "metadata": {},
68
- "outputs": [
69
- {
70
- "name": "stdout",
71
- "output_type": "stream",
72
- "text": [
73
- "img.shape: torch.Size([8, 2, 224, 224]), label: 0\n"
74
- ]
75
- }
76
- ],
77
- "source": [
78
- "img, label = train_dataset[0]\n",
79
- "print(f'img.shape: {img.shape}, label: {label}') # [T=8, p=2, H, W]"
80
- ]
81
- }
82
- ],
83
- "metadata": {
84
- "kernelspec": {
85
- "display_name": "pytorch291",
86
- "language": "python",
87
- "name": "python3"
88
- },
89
- "language_info": {
90
- "codemirror_mode": {
91
- "name": "ipython",
92
- "version": 3
93
- },
94
- "file_extension": ".py",
95
- "mimetype": "text/x-python",
96
- "name": "python",
97
- "nbconvert_exporter": "python",
98
- "pygments_lexer": "ipython3",
99
- "version": "3.11.14"
100
- }
101
- },
102
- "nbformat": 4,
103
- "nbformat_minor": 2
104
- }