View all-cnn-resnet.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 | |
from torch import Tensor | |
import torch.nn as nn | |
from .._internally_replaced_utils import load_state_dict_from_url | |
from typing import Type, Any, Callable, Union, List, Optional | |
__all__ = ['ResNet', 'resnet18', 'resnet34', 'resnet50', 'resnet101', | |
'resnet152', 'resnext50_32x4d', 'resnext101_32x8d', |
View hash-table.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://www.programiz.com/dsa/hash-table | |
# Python program to demonstrate working of HashTable | |
hashTable = [[],] * 10 | |
def checkPrime(n): | |
if n == 1 or n == 0: | |
return 0 | |
for i in range(2, n//2): |
View linked-list.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
# Linked list implementation in Python | |
# https://www.programiz.com/dsa/linked-list | |
# Linked list operations in Python | |
# Create a node | |
class Node: | |
def __init__(self, data): | |
self.data = data | |
self.next = None |
View queue.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://www.programiz.com/dsa/queue | |
# Queue implementation in Python | |
class Queue: | |
def __init__(self): | |
self.queue = [] | |
# Add an element |
View stack.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
# Stack implementation in python | |
# https://www.programiz.com/dsa/stack | |
# Creating a stack | |
def create_stack(): | |
stack = [] | |
return stack | |
# Creating an empty stack |
View AdaIN_dataset.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 os | |
import glob | |
import numpy as np | |
from tqdm import tqdm | |
import torch | |
from torch.utils.data import Dataset | |
from torchvision import transforms | |
from PIL import Image | |
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], |
View AdaIN_test.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 os | |
import argparse | |
from PIL import Image | |
import torch | |
from torchvision import transforms | |
from torchvision.utils import save_image | |
from model import Model | |
output_folder = 'output_image' | |
if os.path.isfile(output_folder): |
View modify_pytorch_output.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 testing(UnNormalize, writer, val_loader, model, criterion, args, size_val_df, y_pred, y_true): | |
batch_time = AverageMeter('Time', ':6.3f') | |
losses = AverageMeter('Loss', ':.4e') | |
top1 = AverageMeter('Acc@1', ':6.2f') | |
top5 = AverageMeter('Acc@5', ':6.2f') | |
progress = ProgressMeter( | |
len(val_loader), | |
[batch_time, losses, top1, top5], | |
prefix='Test: ') |
View tsne_mobilenetv2.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
for i, (img, target,_) in enumerate(tqdm(dataloader)): | |
feat_list = [] | |
def hook(module, input, output): | |
# 由於MobileNetv2不像ResNet18有宣告self.avgpool(),因此我的作法是將模型卷積層的最後一層的輸出手動進行adaptive_avg_pool2d | |
# 接著將它加到feature_list中 | |
feat_list.append(nn.functional.adaptive_avg_pool2d(output.clone(), (1, 1)).reshape(output.clone().shape[0], -1).detach()) | |
View check-image-path-in-dataloader.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
class CustomDataset(torch.utils.data.Dataset): | |
def __init__(self, dataframe, transform): | |
self.dataframe = dataframe | |
self.transform = transform | |
def __len__(self): | |
return len(self.dataframe) | |
def __getitem__(self, index): | |
row = self.dataframe.iloc[index] |