-
Notifications
You must be signed in to change notification settings - Fork 4
# 48 ResNet 모델과 typo 수정 #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ronalmoo
wants to merge
44
commits into
DeepBaksuVision:develop
Choose a base branch
from
Ronalmoo:48
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
a583155
# First commit
Ronalmoo fcb8508
CNN Model
Ronalmoo 3364dc6
add argparse
Ronalmoo dc55d07
Merge remote-tracking branch 'upstream/develop'
Ronalmoo ea7a5e8
repository hierarchy reconstructed
Ronalmoo 8ecd211
Re-construct hierarchy (#11)
ssaru 574e269
add ResNet50
Ronalmoo 943e85f
Use GPU
Ronalmoo 28a7fc1
test
Ronalmoo f2d8c74
minor fixed
Ronalmoo 6de5887
add train_acc
Ronalmoo b3e85a5
add test.py
Ronalmoo 6433bd1
add validation_set_loader
Ronalmoo afc72c9
validate
Ronalmoo 5ce21d4
add confusion_matrix
Ronalmoo 00f6e5e
add validation
Ronalmoo 933f67c
minor change
Ronalmoo 702eaa8
minor change
Ronalmoo 693c81d
split data into train, validation, test
Ronalmoo 4539c07
remove metrics.py
Ronalmoo c9a39af
Merge pull request #35 from chromatices/develop
chromatices 0c22a0f
Merge branch 'master' of https://github.com/DeepBaksuVision/BinaryCon…
Ronalmoo f119606
Merge branch 'develop' of https://github.com/DeepBaksuVision/BinaryCo…
Ronalmoo 3f24d24
add aug module with albumentations
Ronalmoo e60db94
Merge remote-tracking branch 'origin/master'
Ronalmoo 6832bd9
fix dataloader
Ronalmoo 83b87c9
변경 사항에 대한 커밋 메시지를 입력하십시오. '#' 문자로 시작하는
Ronalmoo 0ebaacd
delete train
Ronalmoo fb7e9ac
delete validate
Ronalmoo b7df5c0
delete resnet
Ronalmoo 53433a5
add BinaryLinear
Ronalmoo 46330c8
add binarized_conv
Ronalmoo 4e0eed0
add binarized_linear
Ronalmoo d4fa978
add aug module with albumentation
Ronalmoo 3a24004
add aug module with albumentations
Ronalmoo 4b50002
Merge remote-tracking branch 'upstream/develop'
Ronalmoo 142794d
change configurations
Ronalmoo 5035938
resnet with pytorch_lightning
Ronalmoo 6715801
Merge branch 'develop' of https://github.com/DeepBaksuVision/BinaryCo…
Ronalmoo 6235784
ResNet with pytorch lightning
Ronalmoo f4ff94d
Revert "change configurations"
Ronalmoo 6550c5a
Delete augmetations
Ronalmoo c47bf11
fixed typo
Ronalmoo 05e54fb
fixed typo
Ronalmoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| import os | ||
| import torch | ||
| import torch.nn as nn | ||
| import pytorch_lightning as pl | ||
| import torch.nn.functional as F | ||
| import torchvision.transforms as transforms | ||
| from torch.utils.data import DataLoader | ||
| from pytorch_lightning import Trainer | ||
| from torchvision.datasets import CIFAR10, MNIST | ||
|
|
||
|
|
||
| def conv3x3(in_channels, out_channels, stride=1): | ||
| return nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=stride, | ||
| padding=1, bias=False) | ||
|
Comment on lines
+12
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그냥 호불호인데 이렇게까지 분리 안해도 될 거 같긴한데.. ㅎㅎ |
||
|
|
||
|
|
||
| class ResidualBlock(nn.Module): | ||
| def __init__(self, in_channels, out_channels, stride=1, downsample=None): | ||
| super(ResidualBlock, self).__init__() | ||
| self.conv1 = conv3x3(in_channels, out_channels, stride) | ||
| self.bn1 = nn.BatchNorm2d(out_channels) | ||
| self.relu = nn.ReLU(inplace=True) | ||
| self.conv2 = conv3x3(out_channels, out_channels) | ||
| self.bn2 = nn.BatchNorm2d(out_channels) | ||
| self.downsample = downsample | ||
|
|
||
| def forward(self, x): | ||
| residual = x | ||
| out = self.conv1(x) | ||
| out = self.bn1(out) | ||
| out = self.relu(out) | ||
| out = self.conv2(out) | ||
| out = self.bn2(out) | ||
| if self.downsample: | ||
| residual = self.downsample(x) | ||
| out += residual | ||
| out = self.relu(out) | ||
| return out | ||
|
|
||
|
|
||
| class Bottleneck(nn.Module): | ||
| expansion = 4 | ||
|
|
||
| def __init__(self, in_planes, planes, stride=1): | ||
| super(Bottleneck, self).__init__() | ||
| self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=1, bias=False) | ||
| self.bn1 = nn.BatchNorm2d(planes) | ||
| self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) | ||
| self.bn2 = nn.BatchNorm2d(planes) | ||
| self.conv3 = nn.Conv2d(planes, self.expansion*planes, kernel_size=1, bias=False) | ||
| self.bn3 = nn.BatchNorm2d(self.expansion*planes) | ||
|
|
||
| self.shortcut = nn.Sequential() | ||
| if stride != 1 or in_planes != self.expansion*planes: | ||
| self.shortcut = nn.Sequential( | ||
| nn.Conv2d(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False), | ||
| nn.BatchNorm2d(self.expansion*planes) | ||
| ) | ||
|
|
||
| def forward(self, x): | ||
| out = F.relu(self.bn1(self.conv1(x))) | ||
| out = F.relu(self.bn2(self.conv2(out))) | ||
| out = self.bn3(self.conv3(out)) | ||
| out += self.shortcut(x) | ||
| out = F.relu(out) | ||
| return out | ||
|
|
||
|
|
||
| class ResNet(pl.LightningModule): | ||
| def __init__(self, block, num_blocks, num_classes=10): | ||
| super(ResNet, self).__init__() | ||
| self.in_planes = 64 | ||
|
|
||
| self.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False) | ||
| self.bn1 = nn.BatchNorm2d(64) | ||
| self.layer1 = self._make_layer(block, 64, num_blocks[0], stride=1) | ||
| self.layer2 = self._make_layer(block, 128, num_blocks[1], stride=2) | ||
| self.layer3 = self._make_layer(block, 256, num_blocks[2], stride=2) | ||
| self.layer4 = self._make_layer(block, 512, num_blocks[3], stride=2) | ||
| self.linear = nn.Linear(512 * block.expansion, num_classes) | ||
|
|
||
| def _make_layer(self, block, planes, num_blocks, stride): | ||
| strides = [stride] + [1] * (num_blocks - 1) | ||
| layers = [] | ||
| for stride in strides: | ||
| layers.append(block(self.in_planes, planes, stride)) | ||
| self.in_planes = planes * block.expansion | ||
| return nn.Sequential(*layers) | ||
|
|
||
| def forward(self, x): | ||
| out = F.relu(self.bn1(self.conv1(x))) | ||
| out = self.layer1(out) | ||
| out = self.layer2(out) | ||
| out = self.layer3(out) | ||
| out = self.layer4(out) | ||
| out = F.avg_pool2d(out, 4) | ||
| out = out.view(out.size(0), -1) | ||
| out = self.linear(out) | ||
| return out | ||
|
|
||
| def training_step(self, batch, batch_nb): | ||
| x, y = batch | ||
| y_hat = self.forward(x) | ||
| return {'loss': F.cross_entropy(y_hat, y)} | ||
|
|
||
| def validation_step(self, batch, batch_nb): | ||
| x, y = batch | ||
| y_hat = self.forward(x) | ||
| return {'val_loss': F.cross_entropy(y_hat, y)} | ||
|
|
||
| def validation_end(self, outputs): | ||
| avg_loss = torch.stack([x['val_loss'] for x in outputs]).mean() | ||
| return {'avg_val_loss': avg_loss} | ||
|
|
||
| def test_step(self, batch, batch_nb): | ||
| x, y = batch | ||
| y_hat = self.forward(x) | ||
| return {'test_loss': F.cross_entropy(y_hat, y)} | ||
|
|
||
| def test_end(self, outputs): | ||
| avg_loss = torch.stack([x['test_loss'] for x in outputs]).mean() | ||
| return {'avg_test_loss': avg_loss} | ||
|
|
||
| def configure_optimizers(self): | ||
| return torch.optim.Adam(self.parameters(), lr=0.02) | ||
|
|
||
| @pl.data_loader | ||
| def train_dataloader(self): | ||
| return DataLoader(CIFAR10(os.getcwd(), train=True, transform=transforms.ToTensor(), download=True), batch_size=128) | ||
|
|
||
| @pl.data_loader | ||
| def val_dataloader(self): | ||
| return DataLoader(CIFAR10(os.getcwd(), train=True, transform=transforms.ToTensor(), download=True), batch_size=32) | ||
|
|
||
| @pl.data_loader | ||
| def test_dataloader(self): | ||
| return DataLoader(CIFAR10(os.getcwd(), train=False, download=True), batch_size=32) | ||
|
|
||
|
|
||
| def ResNet50(): | ||
| return ResNet(Bottleneck, [3,4,6,3]) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') | ||
|
|
||
| model = ResNet50() | ||
| trainer = Trainer() | ||
| trainer.fit(model) | ||
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CIFAR-10인데
classes = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")은 무엇일까요?