Skip to content

Instantly share code, notes, and snippets.

View minesh1291's full-sized avatar
🚖
On The Journey to Neverland

Minesh A. Jethva minesh1291

🚖
On The Journey to Neverland
View GitHub Profile
import json
import numpy as np
from pycocotools import mask
from skimage import measure
ground_truth_binary_mask = np.array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
[ 0, 0, 0, 0, 0, 1, 1, 1, 0, 0],
@jph00
jph00 / copilot_torch.py
Created July 18, 2021 01:18
This is the code that copilot nearly entirely auto-generates for a function called `finetune` and a 1-line docstring
# I added all the imports by hand
import torch
from torchvision.datasets import ImageFolder
from torchvision import transforms,models
from torch import nn,optim
# For all functions including this one, I wrote the name and docstring, and sometimes also the param names
def finetune(folder, model):
"""fine tune pytorch model using images from folder and report results on validation set"""
if not os.path.exists(folder): raise ValueError(f"{folder} does not exist")
@mlaves
mlaves / pyro_classification.ipynb
Last active March 8, 2024 05:37
Simple Classification Example in Pyro with SVI and MCMC
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@epignatelli
epignatelli / torch.utils.data.dataset.py
Last active March 24, 2023 15:30
pytorch Subset to return an instance of the parent Dataset, to be able to access the same attribute
"""
An implementation of the pytorch Subset that returns an instance of the original dataset with a reduced number of items.
This has two benefits:
- It allows to stil access the attributes of the Dataset class, such as methods, or properties.
- You can use the usual python index notation with slices to chunk the dataset, rather than creating a list of indices
"""
class Dataset(object):
def __init__(self, iterable):
self.items = iterable
@danallison
danallison / with_sql_session.py
Last active April 23, 2024 07:32
Connect to Postgresql locally or through SSH tunnel
from sshtunnel import SSHTunnelForwarder
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from functools import wraps
# secrets.py contains credentials, etc.
import secrets
def get_engine_for_port(port):
return create_engine('postgresql://{user}:{password}@{host}:{port}/{db}'.format(
@jeremyjordan
jeremyjordan / sgdr.py
Last active December 4, 2023 13:41
Keras Callback for implementing Stochastic Gradient Descent with Restarts
from keras.callbacks import Callback
import keras.backend as K
import numpy as np
class SGDRScheduler(Callback):
'''Cosine annealing learning rate scheduler with periodic restarts.
# Usage
```python
schedule = SGDRScheduler(min_lr=1e-5,
@jayspeidell
jayspeidell / kaggle_download.py
Last active July 18, 2023 12:23
Sample script to download Kaggle files
# Info on how to get your api key (kaggle.json) here: https://github.com/Kaggle/kaggle-api#api-credentials
!pip install kaggle
api_token = {"username":"USERNAME","key":"API_KEY"}
import json
import zipfile
import os
with open('/content/.kaggle/kaggle.json', 'w') as file:
json.dump(api_token, file)
!chmod 600 /content/.kaggle/kaggle.json
!kaggle config path -p /content
@mmngreco
mmngreco / ts_analysis.md
Last active August 8, 2022 02:20
[Methods to improve Time series forecast] #timeseries #python #forecasting
@santi-pdp
santi-pdp / Hello PyTorch.ipynb
Created January 24, 2018 17:53
Toy example in pytorch for binary classification
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kmclaugh
kmclaugh / Keras_Linear_Model.py
Last active February 4, 2021 15:13
Keras Model for a Simple Linear Function (ie Keras modeling a linear regression)
import pandas as pd
import numpy as np
import seaborn as sns
from keras.layers import Dense
from keras.models import Model, Sequential
from keras import initializers
## ---------- Create our linear dataset ---------------
## Set the mean, standard deviation, and size of the dataset, respectively