View 防止Google Colab自动断开代码.js
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
// 每60分钟自动运行代码刷新,解除90分钟断开限制. | |
// 使用方法:colab页面按下 F12或者 Ctrl+Shift+I (mac按 Option+Command+I) 在console(控制台) 输入以下代码并回车. | |
// 复制以下代码粘贴在浏览器console!!不要关闭浏览器以免失效 | |
function ConnectButton(){ | |
console.log("Connect pushed"); | |
document.querySelector("#connect").click() | |
} | |
setInterval(ConnectButton,60000); |
View PyTorch_t-SNE.py
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 tsnecuda import TSNE | |
from tsne.resnet import ResNet18 | |
# 使用 PyTorch內建的 ResNet18 | |
import os | |
import torch | |
import torchvision.models as models | |
import torch.optim | |
from torchvision import transforms | |
model = models.resnet18() |
View TensorFlow_Load_Image_from_Dataframe.py
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/63761717/load-image-dataset | |
# https://stackoverflow.com/questions/60655280/how-to-split-an-image-dataset-in-x-train-y-train-x-test-y-test-by-tensorflow | |
import tensorflow as tf | |
import pandas as pd | |
train_df = pd.read_csv('train.csv') | |
train_df['class'] = train_df['class'].apply(str) | |
train_datagen = tf.keras.preprocessing.image.ImageDataGenerator(horizontal_flip=True, vertical_flip=True,) |
View overkill_leakage.py
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
# 針對每個元件計算其Overkill rate和Leakage rate | |
# 目前只適用於batch size = 1的情形 | |
# 用來產生overkill和leakage數值的dataframe | |
import pandas as pd | |
import torch | |
test_df_mapping2_label = test_df.copy() #複製一份要mapping到2個label的testing資料 | |
test_df_mapping2_label.loc[test_df_mapping2_label['class'] == 0, 'class'] = 0 #將大於1的label轉成1 | |
test_df_mapping2_label.loc[test_df_mapping2_label['class'] == 1, 'class'] = 1 | |
test_df_mapping2_label.loc[test_df_mapping2_label['class'] == 2, 'class'] = 1 |
View searchPPT.py
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://stackoverflow.com/questions/55497789/find-a-word-in-multiple-powerpoint-files-python/55763992#55763992 | |
from pptx import Presentation | |
from pptx.enum.shapes import MSO_SHAPE_TYPE | |
import os | |
path = "./" | |
files = [x for x in os.listdir(path) if x.endswith(".pptx")] |
View RocAucScore.py
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 | |
from sklearn import metrics | |
from sklearn.metrics import roc_auc_score | |
y = np.array([1, 1, 2, 2]) | |
#scores可以是模型預測結果(Label) | |
#scores也可以是模型預測的confidence(softmax probability) | |
scores = np.array([1, 1, 2, 2]) | |
scores = np.array([0.1, 0.4, 0.35, 0.8]) | |
area_under_curve = roc_auc_score(y, scores) |
View decisionBoundary.py
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
def eval(loader, gt_labels_t, output_file="output.txt"): | |
G.eval() # 特徵提取器 | |
F1.eval() # 分類器 | |
size = 0 | |
correct = 0 | |
y_pred=[] | |
y_true=[] | |
pred_prob = None | |
pred_result = None |
View FocalLoss.py
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.nn.functional as F | |
import torch | |
import numpy as np | |
from torch.autograd import Function | |
import torch.nn as nn | |
from pdb import set_trace as breakpoint | |
import sys | |
import math | |
from torch.nn.parameter import Parameter | |
from torch.nn import init |
View LabelSmoothing_public.py
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
# LabelSmoothing.py | |
# https://www.aiuai.cn/aifarm1333.html 示例 3 | |
# From: Github - NVIDIA/DeepLearningExamples/PyTorch/Classification | |
# smoothing.py | |
import torch | |
import torch.nn as nn | |
# 一般版本LabelSmoothing | |
class LabelSmoothing(nn.Module): |
View multiple-y-axis-value-in-same-plot.py
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/45925049/13369757 | |
import matplotlib.pyplot as plt | |
import numpy as np | |
fig, host = plt.subplots(figsize=(12,10)) # (width, height) in inches | |
par1 = host.twinx() | |
par2 = host.twinx() | |
host.set_xlabel("Threshold") |
NewerOlder