By: Gurchetan Singh
SOURCE: https://www.analyticsvidhya.com/blog/2018/02/time-series-forecasting-methods/
| #!/bin/bash | |
| # Check if the script is run with root privileges | |
| if [ "$EUID" -ne 0 ]; then | |
| echo "Please run as root" | |
| exit | |
| fi | |
| # Determine the log file based on the distribution | |
| if [ -f /var/log/auth.log ]; then |
| 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/