View imagenet_idx2class.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
{0: 'tench, Tinca tinca', | |
1: 'goldfish, Carassius auratus', | |
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias', | |
3: 'tiger shark, Galeocerdo cuvieri', | |
4: 'hammerhead, hammerhead shark', | |
5: 'electric ray, crampfish, numbfish, torpedo', | |
6: 'stingray', | |
7: 'cock', | |
8: 'hen', | |
9: 'ostrich, Struthio camelus', |
View imagenet_class2idx.json
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
{ | |
"tench": 0, | |
"goldfish": 1, | |
"great white shark": 2, | |
"tiger shark": 3, | |
"hammerhead": 4, | |
"electric ray": 5, | |
"stingray": 6, | |
"cock": 7, | |
"hen": 8, |
View test_requires_grad.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 | |
x1 = torch.tensor(1.).requires_grad_(True) | |
x2 = torch.tensor(2.).requires_grad_(True) | |
w = torch.tensor(3.).requires_grad_(False) | |
y1 = w * x1 | |
loss1 = torch.mean((y1-1)**2) | |
loss1.backward() |
View resize.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 | |
from PIL import Image | |
import argparse | |
import time | |
import datetime | |
def main(config): | |
src_dir = config.src_dir | |
filenames = os.listdir(src_dir) |
View count_files_for_each_dir.sh
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
find . -type d -print0 | while read -d '' -r dir; do | |
files=("$dir"/*) | |
printf "%5d files in directory %s\n" "${#files[@]}" "$dir" | |
done |
View non_local.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 torch.nn.utils import spectral_norm | |
import torch.nn.functional as F | |
import torch.nn as nn | |
import torch | |
class NonLocalBlock(nn.Module): | |
"""Non-local block.""" | |
def __init__(self, conv_dim): | |
super(NonLocalBlock, self).__init__() |
View contextual_loss.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 contextual_loss(x, y, h=0.5): | |
"""Computes contextual loss between x and y. | |
Args: | |
x: features of shape (N, C, H, W). | |
y: features of shape (N, C, H, W). | |
Returns: | |
cx_loss = contextual loss between x and y (Eq (1) in the paper) | |
""" |
View google_crawler.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
# pip install icrawler | |
from icrawler.builtin import GoogleImageCrawler | |
from datetime import date | |
google_crawler = GoogleImageCrawler(parser_threads=2, downloader_threads=3, | |
storage={'root_dir': './husky'}) # directory where images are downloaded | |
google_crawler.crawl(keyword='Siberian husky', max_num=1000, # max_num should be equal or less than 1000 | |
date_min=date(2012, 3, 1), date_max=date(2012, 6, 1), # you can change date to get more than 1000 images |
View download_flickr_image.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
# First, you should install flickrapi | |
# pip install flickrapi | |
import flickrapi | |
import urllib | |
from PIL import Image | |
# Flickr api access key | |
flickr=flickrapi.FlickrAPI('c6a2c45591d4973ff525042472446ca2', '202ffe6f387ce29b', cache=True) |
View attn_prob_summation.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 | |
import numpy as np | |
# Hyper-parameters | |
vocab_size = 10 | |
batch_size = 3 | |
seq_length = 4 | |
# Generate random indices of range [0, vocab_size) | |
word_indices = torch.from_numpy(np.random.randint(low=0, high=vocab_size, size=(batch_size, seq_length))).view(-1) |
NewerOlder