fje isfhdifhsifs

This commit is contained in:
MTFTau-5 2024-10-26 11:34:07 +08:00
parent 2d78b097a3
commit db33e84265
1086 changed files with 406 additions and 6 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

0
matplotlib Normal file
View File

BIN
model.pth Normal file

Binary file not shown.

1
myenv/bin/python Symbolic link
View File

@ -0,0 +1 @@
python3

1
myenv/bin/python3 Symbolic link
View File

@ -0,0 +1 @@
/usr/bin/python3

1
myenv/bin/python3.10 Symbolic link
View File

@ -0,0 +1 @@
python3

1
myenv/lib64 Symbolic link
View File

@ -0,0 +1 @@
lib

3
myenv/pyvenv.cfg Normal file
View File

@ -0,0 +1,3 @@
home = /usr/bin
include-system-site-packages = false
version = 3.10.12

70
read_data.py Normal file
View 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()

View File

@ -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
View File

@ -0,0 +1 @@
python3

1
venv_2/bin/python3 Symbolic link
View File

@ -0,0 +1 @@
/home/mtftau-5/workplace/.venv/bin/python3

1
venv_2/bin/python3.10 Symbolic link
View File

@ -0,0 +1 @@
python3

1
venv_2/lib64 Symbolic link
View File

@ -0,0 +1 @@
lib

3
venv_2/pyvenv.cfg Normal file
View File

@ -0,0 +1,3 @@
home = /home/mtftau-5/workplace/.venv/bin
include-system-site-packages = false
version = 3.10.12

0
插件/nn Normal file
View File

0
插件/np Normal file
View File

0
插件/os Normal file
View File

0
插件/plt Normal file
View File

0
插件/sympy Normal file
View File

0
插件/torch Normal file
View File

0
插件/torchvision Normal file
View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 170 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Some files were not shown because too many files have changed in this diff Show More