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 tensorflow.python import pywrap_tensorflow | |
# Get weights or whatever you want. | |
# Notice the filename should be full pathname, e.g. './model-7000' | |
def get_weights(filename): | |
reader = pywrap_tensorflow.NewCheckpointReader(filename) | |
var_to_shape_map = reader.get_variable_to_shape_map() | |
weights = [reader.get_tensor(key) for key in var_to_shape_map if 'weights' in key] | |
return weights |
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 Structure: | |
# Class variable that specifies expected fields. | |
_fields= [] | |
def __init__(self, *args): | |
if len(args) != len(self._fields): | |
raise TypeError('Expected {} arguments'.format(len(self._fields))) | |
# Set the arguments. | |
for name, value in zip(self._fields, args): |
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
#!/usr/bin/env python | |
"""Simple HTTP Server With Upload implemented by Python 2. | |
This module builds on BaseHTTPServer by implementing the standard GET | |
and HEAD requests in a fairly straightforward manner. | |
""" | |
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
%% Direct reconstruction | |
I = iradon(proj, 1); | |
subplot(211) | |
imshow(I) | |
title('Reconstructed `iradon`'); | |
%% Manually implement |
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
# Fintune models while add some new modules. | |
class Customize(nn.Module): | |
def __init__(self, pre_model): | |
"""Load the pretrained model, replace the last fc layers and add some new layers.""" | |
super(Customize, self).__init__() | |
self.features = pre_model | |
# If freeze previous weights | |
# ------------------------------------------- |
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 urllib | |
from tqdm import tqdm | |
def check_profanity(filename='./notes.txt'): | |
bad_words = [] | |
with open(filename, 'r') as notes: | |
for line in notes: | |
# See whether read words well | |
for word in tqdm(line.split()): | |
# Check profanity |
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 mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes | |
from mpl_toolkits.axes_grid1.inset_locator import mark_inset | |
# E.g., plot focal loss | |
def focal_loss(p, gamma): | |
return -np.power((1 - p), gamma) * np.log(p) | |
fig, ax = plt.subplots(figsize=[16, 5]) | |
[ax.plot(xs, focal_loss(xs, g), label='$\gamma = {}$'.format(g)) for g in [0, 0.5, 1, 2, 5]] | |
ax.set_xlabel('') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 json | |
from pathlib import Path | |
from tqdm import tqdm | |
from itertools import groupby | |
train_data_root = Path('/data1/kimmyzeng/dataset/Detect_COCO/train/JPEGIMAGES') | |
train_json_file = Path('../data/Detect_COCO/train_instances.json') | |
trainall_odgt = Path('../data/Detect_COCO/odformat/vehicle_trainall.odgt') |
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
# Your snippets | |
# | |
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to | |
# expand the prefix into a larger code block with templated values. | |
# | |
# You can create a new snippet in this file by typing "snip" and then hitting | |
# tab. | |
# | |
# An example CoffeeScript snippet to expand log to console.log: | |
# |
OlderNewer