Skip to content

Instantly share code, notes, and snippets.

View gsoykan's full-sized avatar
🦝
🐪🐫🐪🐫🐪🐫🐪🐫🐪🐫🐪🐫🐪🐫🐪🐫

Gürkan Soykan gsoykan

🦝
🐪🐫🐪🐫🐪🐫🐪🐫🐪🐫🐪🐫🐪🐫🐪🐫
View GitHub Profile
@gsoykan
gsoykan / ListScrollingProxy.swift
Last active May 21, 2022 10:07
ListScrollingProxy update for SwiftUI ScrollView programmatic scrolling
//
// ListScrollingProxy.swift
//
// Created by gurkan soykan on 20.05.2022.
//
// source: https://stackoverflow.com/questions/60855852/how-to-scroll-list-programmatically-in-swiftui/60855853#60855853
import Foundation
import UIKit
@gsoykan
gsoykan / show_img_with_bb.py
Last active October 26, 2022 15:42
shows an image with a bounding box
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from PIL import Image
# source: https://stackoverflow.com/a/37437395/8265079
x_0, y_0, x_1, y_1 = annotation_item['bounding_box']
im = Image.open('my_img.png')
# Create figure and axes
@gsoykan
gsoykan / get_iou.py
Created October 31, 2022 12:32
calculating iou
def get_iou(a, b, epsilon=1e-5):
""" Given two boxes `a` and `b` defined as a list of four numbers:
[x1,y1,x2,y2]
where:
x1,y1 represent the upper left corner
x2,y2 represent the lower right corner
It returns the Intersect of Union score for these two boxes.
source: http://ronny.rest/tutorials/module/localization_001/iou/
Args:
@gsoykan
gsoykan / crop_img.py
Created November 3, 2022 10:01
crops an image and saves
# Importing Image class from PIL module
from PIL import Image
# Opens a image in RGB mode
im = Image.open(r"C:\Users\Admin\Pictures\network.png")
# Setting the points for cropped image
left = 155
top = 65
right = 360
@gsoykan
gsoykan / ncdu.ssh
Created December 27, 2022 14:27
ncdu ssh scanning for kuacc cluster
ssh -C [email protected] ncdu -o- /kuacc/users/gsoykan20 | ncdu -f-
@gsoykan
gsoykan / tensor_2_cv2.py
Created March 10, 2023 19:23
pt tensor to cv2 image
import cv2
import numpy as np
import torch
# Create a random torch tensor
tensor = torch.randn(3, 256, 256)
# Convert the tensor to a numpy array
numpy_image = tensor.numpy()
@gsoykan
gsoykan / change_optimizer_in_mid.py
Last active March 20, 2023 13:05
changing optimizer and scheduler during training
import pytorch_lightning as pl
from torch.optim import Adam
from torch.optim.lr_scheduler import StepLR
class MyModel(pl.LightningModule):
def __init__(self):
super().__init__()
self.layer1 = nn.Linear(10, 5)
self.layer2 = nn.Linear(5, 1)
self.loss_fn = nn.MSELoss()
@gsoykan
gsoykan / bresenham_torch.py
Created April 7, 2023 15:42
Bresenham's line algorithm in PyTorch to connect points in a mask
def draw_line_in_mask(mask, start_point, end_point):
# Extract x and y coordinates of start and end points
x0, y0 = start_point[0], start_point[1]
x1, y1 = end_point[0], end_point[1]
# Compute differences between start and end points
dx = abs(x1 - x0)
dy = abs(y1 - y0)
# Determine direction of the line
@gsoykan
gsoykan / draw_line_in_mask_batched.py
Created May 7, 2023 14:11
given a mask draws line from start and end points in batched manner
def draw_line_in_mask_batched(self, mask, start_point, end_point, light_neighboring=True):
"""
Draws a line in the given batch of masks.
Args:
mask (torch.Tensor): Batch of masks with shape (B, H, W)
start_point (List of Tuples): Batch of start points with shape (B, 2)
end_point (List of Tuples): Batch of end points with shape (B, 2)
Returns:
@gsoykan
gsoykan / run_all_py.sh
Created June 30, 2023 19:19
run all .py files in folder ubuntu
find . -name "*.py" -exec python {} \;