This file contains hidden or 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 keras.models import Sequential | |
from keras.layers import Deconv2D, Lambda | |
def cropped_shape(inshape): | |
samples, ch, w, h = inshape | |
return (samples, ch, w - 2, h - 2) | |
mdl = Sequential() | |
mdl.add(Deconv2D(256, input_shape=(1, 7, 7), padding='valid', kernel_size=4, strides=2, data_format="channels_first")) |
This file contains hidden or 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 keras.layers import Input, Dense, Lambda | |
from keras.models import Model | |
def eucl_dist(inputs): | |
x, y = inputs | |
return ((x - y)**2).sum(axis=-1) | |
x = Input((32,)) | |
y1 = Dense(8)(x) | |
y2 = Dense(8)(x) |
This file contains hidden or 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 | |
import sys, os | |
if len(sys.argv) > 1 and sys.argv[1] == "gpu": | |
os.environ["THEANO_FLAGS"] = "device=gpu2, " | |
os.environ["THEANO_FLAGS"] += "dnn.enabled=True, " | |
os.environ["THEANO_FLAGS"] += "lib.cnmem=0.95" | |
from keras.layers import Input, Convolution2D, MaxPooling2D, AveragePooling2D | |
from keras.layers import Flatten, BatchNormalization, Activation | |
from keras.regularizers import l2 | |
from keras.models import Model |
This file contains hidden or 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 sys, os, cv2 | |
import caffe | |
import numpy as np | |
model_file = "YOURNET.prototxt" | |
pretrained = "YOURNET.caffemodel" | |
# Load a pretrained CAFFE neural network and an image, | |
# use the network to extract features from the image, | |
# then save the feature vector to a text file. |