By: Gurchetan Singh
SOURCE: https://www.analyticsvidhya.com/blog/2018/02/time-series-forecasting-methods/
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], |
# 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") |
""" | |
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 |
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( |
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, |
# 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 |
By: Gurchetan Singh
SOURCE: https://www.analyticsvidhya.com/blog/2018/02/time-series-forecasting-methods/
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 |