Commit 7d06ba8c authored by Liuyuxinict's avatar Liuyuxinict

tijiao

parent 3b197eb1
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="1de14600-5bec-46d2-972f-11687490a303" name="Default Changelist" comment="" />
<list default="true" id="1de14600-5bec-46d2-972f-11687490a303" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/data_loader.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/train.py" beforeDir="false" afterPath="$PROJECT_DIR$/train.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
......@@ -14,7 +19,11 @@
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="ProjectId" id="1hp1mgftlnNubdit1AM27vnxPWs" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showExcludedFiles" value="true" />
......@@ -22,6 +31,7 @@
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
......@@ -120,22 +130,22 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="549" y="171" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1658372379078" />
<state width="1515" height="290" key="GridCell.Tab.0.bottom" timestamp="1658494944285">
<state width="1515" height="223" key="GridCell.Tab.0.bottom" timestamp="1658717893280">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1515" height="290" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1658494944285" />
<state width="1515" height="290" key="GridCell.Tab.0.center" timestamp="1658494944285">
<state width="1515" height="223" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1658717893280" />
<state width="1515" height="223" key="GridCell.Tab.0.center" timestamp="1658717893280">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1515" height="290" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1658494944285" />
<state width="1515" height="290" key="GridCell.Tab.0.left" timestamp="1658494944285">
<state width="1515" height="223" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1658717893280" />
<state width="1515" height="223" key="GridCell.Tab.0.left" timestamp="1658717893279">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1515" height="290" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1658494944285" />
<state width="1515" height="290" key="GridCell.Tab.0.right" timestamp="1658494944285">
<state width="1515" height="223" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1658717893279" />
<state width="1515" height="223" key="GridCell.Tab.0.right" timestamp="1658717893280">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1515" height="290" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1658494944285" />
<state width="1515" height="223" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1658717893280" />
<state width="1515" height="290" key="GridCell.Tab.1.bottom" timestamp="1658494944285">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
import torch
import PIL
from PIL import Image
import torch.utils.data as data
from torchvision import datasets, transforms
def My_loader(path):
return PIL.Image.open(path).convert('RGB')
class MyDataset(torch.utils.data.Dataset):
def __init__(self, txt_dir, image_path, transform=None, target_transform=None, loader=My_loader):
data_txt = open(txt_dir, 'r')
imgs = []
for line in data_txt:
line = line.strip()
words = line.split(' ')
imgs.append((words[0], int(words[1].strip())))
self.imgs = imgs
self.transform = transform
self.target_transform = target_transform
self.loader = My_loader
self.image_path = image_path
def __len__(self):
return len(self.imgs)
def __getitem__(self, index):
img_name, label = self.imgs[index]
# label = list(map(int, label))
# print label
# print type(label)
#img = self.loader('/home/vipl/llh/food101_finetuning/food101_vgg/origal_data/images/'+img_name.replace("\\","/"))
img = self.loader(self.image_path + img_name)
# print img
if self.transform is not None:
img = self.transform(img)
# print img.size()
# label =torch.Tensor(label)
# print label.size()
return img, label
# if the label is the single-label it can be the int
# if the multilabel can be the list to torch.tensor
def load_data(image_path, train_dir, test_dir, batch_size):
normalize = transforms.Normalize(mean=[0.5457954, 0.44430383, 0.34424934],
std=[0.23273608, 0.24383051, 0.24237761])
train_transforms = transforms.Compose([
transforms.RandomHorizontalFlip(p=0.5), # default value is 0.5
transforms.RandomRotation(degrees=15),
transforms.ColorJitter(brightness=0.126, saturation=0.5),
transforms.Resize((550, 550)),
transforms.RandomCrop(448),
transforms.ToTensor(),
normalize
])
# transforms of test dataset
test_transforms = transforms.Compose([
transforms.Resize((550, 550)),
transforms.CenterCrop((448, 448)),
transforms.ToTensor(),
normalize
])
train_dataset = MyDataset(txt_dir=train_dir, image_path=image_path, transform=train_transforms)
test_dataset = MyDataset(txt_dir=test_dir, image_path=image_path, transform=test_transforms)
train_loader = torch.utils.data.DataLoader(dataset=train_dataset, batch_size=batch_size, shuffle=True, num_workers=0)
test_loader = torch.utils.data.DataLoader(dataset=test_dataset, batch_size=batch_size//2, shuffle=False, num_workers=0)
return train_dataset, train_loader, test_dataset, test_loader
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment