This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from backtesting import Backtest, Strategy | |
from backtesting.lib import crossover | |
from FinMind.data import DataLoader | |
import pandas as pd | |
import talib | |
from talib import abstract | |
## 取得資料 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from twstock import Stock | |
import argparse | |
def parse(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"--etf_code", type=str, default="00733", | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
RetinaNet model with the MobileNetV3 backbone from | |
Torchvision classification models. | |
Reference: https://github.com/pytorch/vision/blob/main/torchvision/models/detection/retinanet.py#L377-L405 | |
""" | |
import torchvision | |
import torch | |
from torchvision.models.detection import RetinaNet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
import rawpy | |
def pack_raw(raw): | |
im = raw.raw_image_visible.astype(np.float32) | |
im = np.expand_dims(im, axis=2) | |
img_shape = im.shape | |
H = img_shape[0] | |
W = img_shape[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import matplotlib.image | |
def gamma_compression(image): | |
"""Converts from linear to gamma space.""" | |
return np.maximum(image, 1e-8) ** (1.0 / 2.2) | |
def tonemap(image): | |
"""Simple S-curved global tonemap""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
有时我们需要载入之前训练好的模型来训练当前网络,但之前模型和现在网络结构又存在一些不同(相同就更简单了,直接载入就行) | |
可使用如下代码来迁移模型参数: | |
https://zhuanlan.zhihu.com/p/393586665 | |
""" | |
def transfer_model(pretrain_file, model): | |
pretrain_dict = torch.load(pretrain_file) | |
model_dict = model.state_dict() | |
pretrain_dict = transfer_state_dict(pretrain_dict, model_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/mv-lab/AISP/blob/main/mai22-learnedisp/mai-learned-isp-dev.ipynb | |
import numpy as np | |
import pandas as pd | |
import gc | |
import time | |
from glob import glob | |
from tqdm import tqdm | |
from matplotlib import pyplot as plt | |
import pickle | |
import imageio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# init git | |
cd existing_folder | |
git init --initial-branch=main | |
git remote add origin git@gitlab-XXXX.com:yanwei.liu/XXXX-XXXX.git | |
# git commit | |
git add . | |
git commit -m "Initial commit" | |
git push -u origin main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
import torch.nn.functional as F | |
def pad_image_to_nearest_multiple(image, multiple=32): | |
image = torch.from_numpy(image.astype(np.float32)).unsqueeze(0) | |
channels, height, width = image.shape | |
padded_height = ((height + multiple - 1) // multiple) * multiple | |
padded_width = ((width + multiple - 1) // multiple) * multiple | |