Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/icanSeeo/i-can-see into clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun0zo committed Dec 16, 2023
2 parents 4168b4a + 1cad9b2 commit e32020c
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 2 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# name: Python application

# on:
# push:
# branches: [ "CI/CD" ]
# pull_request:
# branches: [ "CI/CD" ]

# permissions:
# contents: read

# jobs:
# build:

# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v3
# - name: Set up Python 3.10
# uses: actions/setup-python@v3
# with:
# python-version: "3.10"
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install flake8 pytest
# pip install torch torchvision
# - name: Lint with flake8
# run: |
# # stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Test with pytest
# run: |
# cd test
# pytest -v
# - name: Build Docker image
# run: docker build -t my-python-app .

# - name: Run tests in Docker container
# run: docker run my-python-app
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python:3.10
WORKDIR /app
COPY . /app
RUN pip install --upgrade pip && pip install flake8 pytest torch torchvision
CMD ["python", "-m", "pytest", "-v", "./test/test_resnet.py"]
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# i-can-see
Attention based CNN
# 🔍 i-can-see
👁‍🗨 Attention based CNN

## 📸 Index
<details open="open">
<ol>
<li> 프로젝트 소개</li>
<li> 기술 스택</li>
<li> 팀원 정보</li>
<li> Doc</li>
</ol>
</details>

## 🐧 프로젝트 소개
<ul>
<li>Attention 기반 CNN 활용한 이미지 Blur 및 Noise 완화</li>
<ul>
<li>Attention~!</li>
</ul>
</ul>

## Team Member
> BigData Project
| Name | Role | Contect |
|:---:|:---:|:---:|
|강성준| slave, 블록체인 개발자 | [email protected] |
|조준영| AI 개발자, 웹디자이너 | [email protected] |
|김동현| slave, 백엔드 개발자 | [email protected] |
Binary file added requirements.txt
Binary file not shown.
70 changes: 70 additions & 0 deletions test/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision
import torchvision.transforms as transforms

def test_training():
# 데이터 전처리
transform = transforms.Compose([
transforms.Resize((32, 32)),
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])

trainset = torchvision.datasets.MNIST(root='./data', train=True, download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)

testset = torchvision.datasets.MNIST(root='./data', train=False, download=True, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=64, shuffle=False)

# ResNet 모델 정의
resnet = torchvision.models.resnet18(pretrained=True)
resnet.conv1 = nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3)
num_ftrs = resnet.fc.in_features
resnet.fc = nn.Linear(num_ftrs, 10)

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

resnet.to(device)

# 손실 함수 및 최적화 함수
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(resnet.parameters(), lr=0.01)

# 모델 학습
num_epochs = 2

for epoch in range(num_epochs):
running_loss = 0.0
resnet.train()

for i, (inputs, labels) in enumerate(trainloader):
inputs, labels = inputs.to(device), labels.to(device)

optimizer.zero_grad()

outputs = resnet(inputs)
loss = criterion(outputs, labels)

loss.backward()
optimizer.step()

running_loss += loss.item()


correct = 0
total = 0
resnet.eval()

with torch.no_grad():
for data in testloader:
images, labels = data
images, labels = images.to(device), labels.to(device)
outputs = resnet(images)
_, predicted = torch.max(outputs.data, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()


assert correct / total >= 0.1, f"Accuracy: {100 * correct / total}%"
70 changes: 70 additions & 0 deletions test/test_resnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision
import torchvision.transforms as transforms

def test_training():
# 데이터 전처리
transform = transforms.Compose([
transforms.Resize((32, 32)),
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])

trainset = torchvision.datasets.MNIST(root='./data', train=True, download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)

testset = torchvision.datasets.MNIST(root='./data', train=False, download=True, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=64, shuffle=False)

# ResNet 모델 정의
resnet = torchvision.models.resnet18(pretrained=True)
resnet.conv1 = nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3)
num_ftrs = resnet.fc.in_features
resnet.fc = nn.Linear(num_ftrs, 10)

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

resnet.to(device)

# 손실 함수 및 최적화 함수
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(resnet.parameters(), lr=0.01)

# 모델 학습
num_epochs = 2

for epoch in range(num_epochs):
running_loss = 0.0
resnet.train()

for i, (inputs, labels) in enumerate(trainloader):
inputs, labels = inputs.to(device), labels.to(device)

optimizer.zero_grad()

outputs = resnet(inputs)
loss = criterion(outputs, labels)

loss.backward()
optimizer.step()

running_loss += loss.item()


correct = 0
total = 0
resnet.eval()

with torch.no_grad():
for data in testloader:
images, labels = data
images, labels = images.to(device), labels.to(device)
outputs = resnet(images)
_, predicted = torch.max(outputs.data, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()


assert correct / total >= 0.1, f"Accuracy: {100 * correct / total}%"
70 changes: 70 additions & 0 deletions test/test_training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision
import torchvision.transforms as transforms

def test_training():
# 데이터 전처리
transform = transforms.Compose([
transforms.Resize((32, 32)),
transforms.ToTensor(),
transforms.Normalize((0.1307,), (0.3081,))
])

trainset = torchvision.datasets.MNIST(root='./data', train=True, download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)

testset = torchvision.datasets.MNIST(root='./data', train=False, download=True, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=64, shuffle=False)

# ResNet 모델 정의
resnet = torchvision.models.resnet18(pretrained=True)
resnet.conv1 = nn.Conv2d(1, 64, kernel_size=7, stride=2, padding=3)
num_ftrs = resnet.fc.in_features
resnet.fc = nn.Linear(num_ftrs, 10)

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

resnet.to(device)

# 손실 함수 및 최적화 함수
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(resnet.parameters(), lr=0.01)

# 모델 학습
num_epochs = 5

for epoch in range(num_epochs):
running_loss = 0.0
resnet.train()

for i, (inputs, labels) in enumerate(trainloader):
inputs, labels = inputs.to(device), labels.to(device)

optimizer.zero_grad()

outputs = resnet(inputs)
loss = criterion(outputs, labels)

loss.backward()
optimizer.step()

running_loss += loss.item()


correct = 0
total = 0
resnet.eval()

with torch.no_grad():
for data in testloader:
images, labels = data
images, labels = images.to(device), labels.to(device)
outputs = resnet(images)
_, predicted = torch.max(outputs.data, 1)
total += labels.size(0)
correct += (predicted == labels).sum().item()


assert correct / total >= 0.9, f"Accuracy: {100 * correct / total}%"

0 comments on commit e32020c

Please sign in to comment.