fje isfhdifhsifs
BIN
MNIST/raw/t10k-images-idx3-ubyte
Normal file
BIN
MNIST/raw/t10k-images-idx3-ubyte.gz
Normal file
BIN
MNIST/raw/t10k-labels-idx1-ubyte
Normal file
BIN
MNIST/raw/t10k-labels-idx1-ubyte.gz
Normal file
BIN
MNIST/raw/train-images-idx3-ubyte
Normal file
BIN
MNIST/raw/train-images-idx3-ubyte.gz
Normal file
BIN
MNIST/raw/train-labels-idx1-ubyte
Normal file
BIN
MNIST/raw/train-labels-idx1-ubyte.gz
Normal file
BIN
data/MNIST/raw/t10k-images-idx3-ubyte
Normal file
BIN
data/MNIST/raw/t10k-images-idx3-ubyte.gz
Normal file
BIN
data/MNIST/raw/t10k-labels-idx1-ubyte
Normal file
BIN
data/MNIST/raw/t10k-labels-idx1-ubyte.gz
Normal file
BIN
data/MNIST/raw/train-images-idx3-ubyte
Normal file
BIN
data/MNIST/raw/train-images-idx3-ubyte.gz
Normal file
BIN
data/MNIST/raw/train-labels-idx1-ubyte
Normal file
BIN
data/MNIST/raw/train-labels-idx1-ubyte.gz
Normal file
0
matplotlib
Normal file
1
myenv/bin/python
Symbolic link
@ -0,0 +1 @@
|
||||
python3
|
1
myenv/bin/python3
Symbolic link
@ -0,0 +1 @@
|
||||
/usr/bin/python3
|
1
myenv/bin/python3.10
Symbolic link
@ -0,0 +1 @@
|
||||
python3
|
1
myenv/lib64
Symbolic link
@ -0,0 +1 @@
|
||||
lib
|
3
myenv/pyvenv.cfg
Normal file
@ -0,0 +1,3 @@
|
||||
home = /usr/bin
|
||||
include-system-site-packages = false
|
||||
version = 3.10.12
|
70
read_data.py
Normal file
@ -0,0 +1,70 @@
|
||||
from torch.utils.data import Dataset, DataLoader
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
import os
|
||||
from torchvision import transforms
|
||||
from torch.utils.tensorboard import SummaryWriter
|
||||
from torchvision.utils import make_grid
|
||||
|
||||
writer = SummaryWriter("logs")
|
||||
|
||||
class MyData(Dataset):
|
||||
|
||||
def __init__(self, root_dir, image_dir, label_dir, transform):
|
||||
self.root_dir = root_dir
|
||||
self.image_dir = image_dir
|
||||
self.label_dir = label_dir
|
||||
self.label_path = os.path.join(self.root_dir, self.label_dir)
|
||||
self.image_path = os.path.join(self.root_dir, self.image_dir)
|
||||
self.image_list = os.listdir(self.image_path)
|
||||
self.label_list = os.listdir(self.label_path)
|
||||
self.transform = transform
|
||||
# 因为label 和 Image文件名相同,进行一样的排序,可以保证取出的数据和label是一一对应的
|
||||
self.image_list.sort()
|
||||
self.label_list.sort()
|
||||
|
||||
def __getitem__(self, idx):
|
||||
img_name = self.image_list[idx]
|
||||
label_name = self.label_list[idx]
|
||||
img_item_path = os.path.join(self.root_dir, self.image_dir, img_name)
|
||||
label_item_path = os.path.join(self.root_dir, self.label_dir, label_name)
|
||||
img = Image.open(img_item_path)
|
||||
|
||||
with open(label_item_path, 'r') as f:
|
||||
label = f.readline()
|
||||
|
||||
# img = np.array(img)
|
||||
img = self.transform(img)
|
||||
sample = {'img': img, 'label': label}
|
||||
return sample
|
||||
|
||||
def __len__(self):
|
||||
assert len(self.image_list) == len(self.label_list)
|
||||
return len(self.image_list)
|
||||
|
||||
if __name__ == '__main__':
|
||||
transform = transforms.Compose([transforms.Resize((256, 256)), transforms.ToTensor()])
|
||||
root_dir = "dataset/train"
|
||||
image_ants = "ants_image"
|
||||
label_ants = "ants_label"
|
||||
ants_dataset = MyData(root_dir, image_ants, label_ants, transform)
|
||||
image_bees = "bees_image"
|
||||
label_bees = "bees_label"
|
||||
bees_dataset = MyData(root_dir, image_bees, label_bees, transform)
|
||||
train_dataset = ants_dataset + bees_dataset
|
||||
|
||||
# transforms = transforms.Compose([transforms.Resize(256, 256)])
|
||||
dataloader = DataLoader(train_dataset, batch_size=1, num_workers=2)
|
||||
|
||||
writer.add_image('error', train_dataset[119]['img'])
|
||||
writer.close()
|
||||
for i, j in enumerate(dataloader):
|
||||
# imgs, labels = j
|
||||
print(type(j))
|
||||
print(i, j['img'].shape)
|
||||
# writer.add_image("train_data_b2", make_grid(j['img']), i)
|
||||
|
||||
writer.close()
|
||||
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
#这些注释都是原来的错误代码。最后是找了AI 解决的(🤓)
|
||||
import torch
|
||||
from torchvision import datasets, transforms
|
||||
from torch.utils.data import DataLoader
|
||||
from torchvision.datasets import MNIST
|
||||
import matplotlib.pyplot as plt
|
||||
#import matplotlib.pyplot as plt #可有可无
|
||||
|
||||
device = 'cuda:0'
|
||||
class Net(torch.nn.Module):
|
||||
@ -31,7 +32,7 @@ def evaluate(test_data, net):
|
||||
n_total = 0
|
||||
with torch.no_grad():
|
||||
for (x, y) in test_data:
|
||||
# 将数据发送到GPU
|
||||
# 将数据发送到GPU(这个02是没有的)
|
||||
x = x.view(-1, 28 * 28).to(device)
|
||||
y = y.to(device)
|
||||
output = net(x)
|
||||
@ -57,15 +58,15 @@ def main():
|
||||
print('initial accuracy', evaluate(test_data, net))
|
||||
optimizer = torch.optim.Adam(net.parameters())
|
||||
|
||||
for epoch in range(3):
|
||||
for epoch in range(100):
|
||||
for (x, y) in train_data:
|
||||
# 将数据发送到GPU
|
||||
# 将数据发送到GPU(这个02是没有的)
|
||||
x = x.view(-1, 28 * 28).to(device)
|
||||
y = y.to(device)
|
||||
net.zero_grad()
|
||||
output = net(x)
|
||||
loss = torch.nn.functional.nll_loss(output, y)
|
||||
loss.backward()
|
||||
loss.backward()#02没有这个,导致正确率也没有提高
|
||||
optimizer.step()
|
||||
print('epoch', epoch, 'accuracy', evaluate(test_data, net))
|
||||
torch.save(net,'./model.pth')
|
||||
@ -98,4 +99,4 @@ if __name__ == "__main__":
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
1
venv_2/bin/python
Symbolic link
@ -0,0 +1 @@
|
||||
python3
|
1
venv_2/bin/python3
Symbolic link
@ -0,0 +1 @@
|
||||
/home/mtftau-5/workplace/.venv/bin/python3
|
1
venv_2/bin/python3.10
Symbolic link
@ -0,0 +1 @@
|
||||
python3
|
1
venv_2/lib64
Symbolic link
@ -0,0 +1 @@
|
||||
lib
|
3
venv_2/pyvenv.cfg
Normal file
@ -0,0 +1,3 @@
|
||||
home = /home/mtftau-5/workplace/.venv/bin
|
||||
include-system-site-packages = false
|
||||
version = 3.10.12
|
0
插件/torchvision
Normal file
BIN
数据集/data/train/ants_image/0013035.jpg
Normal file
After Width: | Height: | Size: 46 KiB |
BIN
数据集/data/train/ants_image/1030023514_aad5c608f9.jpg
Normal file
After Width: | Height: | Size: 170 KiB |
BIN
数据集/data/train/ants_image/1095476100_3906d8afde.jpg
Normal file
After Width: | Height: | Size: 124 KiB |
BIN
数据集/data/train/ants_image/1099452230_d1949d3250.jpg
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
数据集/data/train/ants_image/116570827_e9c126745d.jpg
Normal file
After Width: | Height: | Size: 140 KiB |
BIN
数据集/data/train/ants_image/1225872729_6f0856588f.jpg
Normal file
After Width: | Height: | Size: 67 KiB |
BIN
数据集/data/train/ants_image/1262877379_64fcada201.jpg
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
数据集/data/train/ants_image/1269756697_0bce92cdab.jpg
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
数据集/data/train/ants_image/1286984635_5119e80de1.jpg
Normal file
After Width: | Height: | Size: 99 KiB |
BIN
数据集/data/train/ants_image/132478121_2a430adea2.jpg
Normal file
After Width: | Height: | Size: 111 KiB |
BIN
数据集/data/train/ants_image/1360291657_dc248c5eea.jpg
Normal file
After Width: | Height: | Size: 139 KiB |
BIN
数据集/data/train/ants_image/1368913450_e146e2fb6d.jpg
Normal file
After Width: | Height: | Size: 89 KiB |
BIN
数据集/data/train/ants_image/1473187633_63ccaacea6.jpg
Normal file
After Width: | Height: | Size: 149 KiB |
BIN
数据集/data/train/ants_image/148715752_302c84f5a4.jpg
Normal file
After Width: | Height: | Size: 100 KiB |
BIN
数据集/data/train/ants_image/1489674356_09d48dde0a.jpg
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
数据集/data/train/ants_image/149244013_c529578289.jpg
Normal file
After Width: | Height: | Size: 107 KiB |
BIN
数据集/data/train/ants_image/150801003_3390b73135.jpg
Normal file
After Width: | Height: | Size: 164 KiB |
BIN
数据集/data/train/ants_image/150801171_cd86f17ed8.jpg
Normal file
After Width: | Height: | Size: 155 KiB |
BIN
数据集/data/train/ants_image/154124431_65460430f2.jpg
Normal file
After Width: | Height: | Size: 104 KiB |
BIN
数据集/data/train/ants_image/162603798_40b51f1654.jpg
Normal file
After Width: | Height: | Size: 57 KiB |
BIN
数据集/data/train/ants_image/1660097129_384bf54490.jpg
Normal file
After Width: | Height: | Size: 164 KiB |
BIN
数据集/data/train/ants_image/167890289_dd5ba923f3.jpg
Normal file
After Width: | Height: | Size: 162 KiB |
BIN
数据集/data/train/ants_image/1693954099_46d4c20605.jpg
Normal file
After Width: | Height: | Size: 73 KiB |
BIN
数据集/data/train/ants_image/175998972.jpg
Normal file
After Width: | Height: | Size: 49 KiB |
BIN
数据集/data/train/ants_image/178538489_bec7649292.jpg
Normal file
After Width: | Height: | Size: 88 KiB |
BIN
数据集/data/train/ants_image/1804095607_0341701e1c.jpg
Normal file
After Width: | Height: | Size: 29 KiB |
BIN
数据集/data/train/ants_image/1808777855_2a895621d7.jpg
Normal file
After Width: | Height: | Size: 112 KiB |
BIN
数据集/data/train/ants_image/188552436_605cc9b36b.jpg
Normal file
After Width: | Height: | Size: 191 KiB |
BIN
数据集/data/train/ants_image/1917341202_d00a7f9af5.jpg
Normal file
After Width: | Height: | Size: 100 KiB |
BIN
数据集/data/train/ants_image/1924473702_daa9aacdbe.jpg
Normal file
After Width: | Height: | Size: 79 KiB |
BIN
数据集/data/train/ants_image/196057951_63bf063b92.jpg
Normal file
After Width: | Height: | Size: 128 KiB |
BIN
数据集/data/train/ants_image/196757565_326437f5fe.jpg
Normal file
After Width: | Height: | Size: 174 KiB |
BIN
数据集/data/train/ants_image/201558278_fe4caecc76.jpg
Normal file
After Width: | Height: | Size: 96 KiB |
BIN
数据集/data/train/ants_image/201790779_527f4c0168.jpg
Normal file
After Width: | Height: | Size: 134 KiB |
BIN
数据集/data/train/ants_image/2019439677_2db655d361.jpg
Normal file
After Width: | Height: | Size: 91 KiB |
BIN
数据集/data/train/ants_image/207947948_3ab29d7207.jpg
Normal file
After Width: | Height: | Size: 186 KiB |
BIN
数据集/data/train/ants_image/20935278_9190345f6b.jpg
Normal file
After Width: | Height: | Size: 40 KiB |
BIN
数据集/data/train/ants_image/224655713_3956f7d39a.jpg
Normal file
After Width: | Height: | Size: 69 KiB |
BIN
数据集/data/train/ants_image/2265824718_2c96f485da.jpg
Normal file
After Width: | Height: | Size: 136 KiB |
BIN
数据集/data/train/ants_image/2265825502_fff99cfd2d.jpg
Normal file
After Width: | Height: | Size: 104 KiB |
BIN
数据集/data/train/ants_image/226951206_d6bf946504.jpg
Normal file
After Width: | Height: | Size: 208 KiB |
BIN
数据集/data/train/ants_image/2278278459_6b99605e50.jpg
Normal file
After Width: | Height: | Size: 136 KiB |
BIN
数据集/data/train/ants_image/2288450226_a6e96e8fdf.jpg
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
数据集/data/train/ants_image/2288481644_83ff7e4572.jpg
Normal file
After Width: | Height: | Size: 127 KiB |
BIN
数据集/data/train/ants_image/2292213964_ca51ce4bef.jpg
Normal file
After Width: | Height: | Size: 142 KiB |
BIN
数据集/data/train/ants_image/24335309_c5ea483bb8.jpg
Normal file
After Width: | Height: | Size: 38 KiB |
BIN
数据集/data/train/ants_image/245647475_9523dfd13e.jpg
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
数据集/data/train/ants_image/255434217_1b2b3fe0a4.jpg
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
数据集/data/train/ants_image/258217966_d9d90d18d3.jpg
Normal file
After Width: | Height: | Size: 94 KiB |
BIN
数据集/data/train/ants_image/275429470_b2d7d9290b.jpg
Normal file
After Width: | Height: | Size: 106 KiB |
BIN
数据集/data/train/ants_image/28847243_e79fe052cd.jpg
Normal file
After Width: | Height: | Size: 61 KiB |
BIN
数据集/data/train/ants_image/318052216_84dff3f98a.jpg
Normal file
After Width: | Height: | Size: 192 KiB |
BIN
数据集/data/train/ants_image/334167043_cbd1adaeb9.jpg
Normal file
After Width: | Height: | Size: 93 KiB |
BIN
数据集/data/train/ants_image/339670531_94b75ae47a.jpg
Normal file
After Width: | Height: | Size: 218 KiB |
BIN
数据集/data/train/ants_image/342438950_a3da61deab.jpg
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
数据集/data/train/ants_image/36439863_0bec9f554f.jpg
Normal file
After Width: | Height: | Size: 19 KiB |