Skip to content

Instantly share code, notes, and snippets.

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])
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'
(Pdb) pdb.set_trace = lambda: None # This replaces the set_trace() function!
(Pdb) continue
@e96031413
e96031413 / iqa_metric.py
Created March 21, 2023 06:15
PyTorch Implementation of IQA metric Including PSNR, SSIM, LPIPS, NIQE, LOE
"""
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
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'
@e96031413
e96031413 / Cumulative_DensityFunction.py
Last active December 12, 2022 03:24
Cumulative density function with Scipy
# 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))
@e96031413
e96031413 / pandas_float_format.py
Created December 6, 2022 12:18
pandas設定float顯示精度
# https://stackoverflow.com/a/46672301/13369757
import pandas as pd
pd.set_option('display.float_format', '{:.2f}'.format)
import scrapetube
import random
import pandas as pd
AllVideoList = []
videos = scrapetube.get_channel("UCJIfeSCssxSC_Dhc5s7woww") # channel ID
titleList = []
urlList = []
while True:
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),
}
# 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