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 imageio | |
def simplest_color_balance(img, percent): | |
out_channels = [] | |
channels = cv2.split(img) | |
for channel in channels: | |
total_pixels = img.shape[0] * img.shape[1] | |
low_val, high_val = np.percentile(channel, [percent, 100 - percent]) |
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 os | |
import xml.etree.ElementTree as ET | |
import csv | |
# Set the paths for the input and output directories | |
voc_path = '/home/Yanwei_Liu/Datasets/PASCALRAW/annotations/' | |
train_img_path = '/home/Yanwei_Liu/Datasets/PASCALRAW/images/train/' | |
val_img_path = '/home/Yanwei_Liu/Datasets/PASCALRAW/images/val/' | |
train_file_path = '/home/Yanwei_Liu/Datasets/PASCALRAW/trainval/train.txt' |
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
(Pdb) pdb.set_trace = lambda: None # This replaces the set_trace() function! | |
(Pdb) continue |
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
""" | |
Implementation of IQA metrics in PyTorch, including PSNR, SSIM, LPIPS, NIQE, and LOE. | |
""" | |
import torch | |
import torch.nn as nn | |
import torchvision.models as models | |
import torchvision.transforms.functional as F | |
from torch.nn.functional import conv2d | |
from IQA_pytorch import SSIM, LPIPSvgg |
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 | |
import numpy as np | |
from sklearn.model_selection import train_test_split | |
from sklearn.linear_model import LinearRegression | |
from sklearn.metrics import mean_absolute_error, mean_squared_error | |
from FinMind.data import DataLoader | |
dl = DataLoader() | |
stock_data = dl.taiwan_stock_daily( | |
stock_id='2330', start_date='2010-01-01', end_date='2022-12-20' |
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://stackoverflow.com/questions/41974615/how-do-i-calculate-pdf-probability-density-function-in-python | |
from scipy.stats import norm | |
print(norm.cdf(x, mean, std)) |
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://stackoverflow.com/a/46672301/13369757 | |
import pandas as pd | |
pd.set_option('display.float_format', '{:.2f}'.format) |
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 scrapetube | |
import random | |
import pandas as pd | |
AllVideoList = [] | |
videos = scrapetube.get_channel("UCJIfeSCssxSC_Dhc5s7woww") # channel ID | |
titleList = [] | |
urlList = [] | |
while True: |
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 bayes_opt import BayesianOptimization | |
from bayes_opt.logger import JSONLogger | |
from bayes_opt.event import Events | |
logger = JSONLogger(path="./tau_logs.json") | |
pbounds = {'tau1': (0.1, 0.2), 'tau2': (0.3, 0.4), | |
'tau3': (0.5, 0.6), 'tau4': (0.7, 0.8), | |
} |
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
# ref: https://blog.csdn.net/MachineLearner/article/details/104587288 | |
def plot_decision_boundary(pred_func, X, y, figure=None): | |
"""Plot a decision boundary""" | |
if figure is None: # If no figure is given, create a new one | |
plt.figure() | |
# Set min and max values and give it some padding | |
x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5 | |
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5 | |
h = 0.01 |