Skip to content

deep image prior #50

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
wants to merge 8 commits into
base: prashansFrontendNew
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/python-cicd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python CI/CD Workflow
name: Prettify CI/CD Workflow

on:
push:
Expand Down Expand Up @@ -28,7 +28,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt

# # - name: Run Python script
# # run: python backend/app.py

Expand Down
3 changes: 2 additions & 1 deletion backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@ def upload_image():


if __name__ == '__main__':
app.run(host='localhost', debug=True, port=8000)
app.run(host='localhost', debug=True, port=8000)
#
54 changes: 54 additions & 0 deletions backend/dip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import torch
import torch.nn as nn
import torchvision.transforms as transforms
from PIL import Image

class DIP(nn.Module):
def _init_(self, img_path, num_channels=64, num_iterations=5000, learning_rate=0.01, print_interval=100):
super()._init_()
self.num_channels = num_channels
self.num_iterations = num_iterations
self.learning_rate = learning_rate
self.print_interval = print_interval

# Load the image
self.img = Image.open(img_path)
self.transform = transforms.Compose([transforms.ToTensor()])
self.img_tensor = self.transform(self.img)

# Create a random input image
self.input_img = torch.randn(self.img_tensor.shape[0], self.num_channels, self.img_tensor.shape[2], self.img_tensor.shape[3])

# Define the network architecture
self.net = nn.Sequential(
nn.Conv2d(self.num_channels, self.num_channels, kernel_size=3, stride=1, padding=1),
nn.ReLU(),
nn.Conv2d(self.num_channels, self.num_channels, kernel_size=3, stride=1, padding=1),
nn.ReLU(),
nn.Conv2d(self.num_channels, self.num_channels, kernel_size=3, stride=1, padding=1),
nn.ReLU(),
nn.Conv2d(self.num_channels, self.img_tensor.shape[0], kernel_size=3, stride=1, padding=1)
)

def forward(self, x):
return self.net(x)

def optimize(self):
optimizer = torch.optim.Adam(self.parameters(), lr=self.learning_rate)

for i in range(self.num_iterations):
optimizer.zero_grad()
output = self.forward(self.input_img)
loss = torch.mean((output - self.img_tensor) ** 2)
loss.backward()
optimizer.step()

if i % self.print_interval == 0:
print('Iteration {}: loss = {}'.format(i, loss.item()))

# Convert the output image tensor to a PIL image
output_img = output.detach().squeeze().permute(1, 2, 0).clamp(0, 1).numpy()
output_img = (output_img * 255).astype('uint8')
output_img = Image.fromarray(output_img)

return output_img
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pycparser==2.21
Pygments==2.14.0
PyJWT==2.6.0
pymongo==4.3.3
pyngrok==5.2.1
pyparsing==3.0.9
pytest==7.2.2
python-dateutil==2.8.2
Expand Down
2 changes: 1 addition & 1 deletion backend/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ def test_update_user(new_user):
updated_user = User("updateduser", "[email protected]",'password')
assert updated_user.name == 'updateduser'
assert updated_user.email == '[email protected]'
assert updated_user.password == 'password'
assert updated_user.password == 'password'