可以说土堆真的保姆级
学习读取数据集中的各类数据
from torch.utils.data import Dataset
from PIL import Image
import os
class MyData(Dataset):
def __init__(self,root_dir,label_dir):
self.root_dir = root_dir
self.label_dir = label_dir
self.path = os.path.join(self.root_dir,self.label_dir)
self.img_path = os.listdir(self.path)
def __getitem__(self, idx):
img_name = self.img_path[idx]
img_item_path=os.path.join(self.root_dir,self.label_dir,img_name)
img = Image.open(img_item_path)
label = self.label_dir
return img,label
def __len__(self):
return len(self.img_path)
root_dir = "dataset/train"
ants_label_dir = "ants"
bees_label_dir = "bees"
ants_dataset = MyData(root_dir,ants_label_dir)
bees_dataset = MyData(root_dir,bees_label_dir)
train_dataset = ants_dataset + bees_dataset
python console
C:\ProgramData\Anaconda3\envs\pytorch\python.exe "C:\D\ccpython\PyCharm Community Edition 2021.3.1\plugins\python-ce\helpers\pydev\pydevconsole.py" --mode=client --port=53938
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['C:\\Users\\26940\\Desktop\\learn_pytorchc', 'C:/Users/26940/Desktop/learn_pytorchc'])
Python 3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 6.1.0
Python 3.6.13 |Anaconda, Inc.| (default, Mar 16 2021, 11:37:27) [MSC v.1916 64 bit (AMD64)] on win32
from torch.utils.data import Dataset
from PIL import Image
import os
class MyData(Dataset):
def __init__(self,root_dir,label_dir):
self.root_dir = root_dir
self.label_dir = label_dir
self.path = os.path.join(self.root_dir,self.label_dir)
self.img_path = os.listdir(self.path)
def __getitem__(self, idx):
img_name = self.img_path[idx]
img_item_path=os.path.join(self.root_dir,self.label_dir,img_name)
img = Image.open(img_item_path)
label = self.label_dir
return img,label
def __len__(self):
return len(self.img_path)
root_dir = "dataset/train"
ants_label_dir = "ants"
ants_dataset = MyData(root_dir,ants_label_dir)
root_dir = "dataset/train"
ants_label_dir = "ants"
bees_label_dir = "bees"
ants_dataset = MyData(root_dir,ants_label_dir)
bees_dataset = MyData(root_dir,bees_label_dir)
train_dataset = ants_dataset + bees_dataset
len(train_dataset)
Out[7]: 245
img,label=train_dataset[124]
img.show()
蜜蜂蚂蚁数据集:
conception 观念
irritate 激怒
lapse 失误
accommodate 容纳
fiber 纤维素
maneuver 演习
intelligible 可理解的
ashore 上岸
amplify 放大
discreet 谨慎的
council 委员会
lateral 侧面的
illustration 例证
breeze 微风
strain 拉紧
marital 夫妻的
indicative 表示的
therapy 治疗
transplant 迁移
moral 道德的
nasty 烦人的
ingenious 精致的
arena 竞技场
explicit 明确的
assimilate 同化
presumably 大概
liberty 自由
stalk 跟踪
stimulate 刺激
ancestor 祖宗
sway 摇摆
evaporate 蒸发
dread 恐惧
terminate 结束
wy补录,投wb,bz
明天一面md