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
| def edit_distance(a, b): | |
| m,n=len(a),len(b) | |
| ins_cost = 1 | |
| del_cost = 1 | |
| cost = {} | |
| for i in range(m+1): | |
| cost[i,0]=i*ins_cost | |
| for j in range(n+1): |
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
| xmax = 2 | |
| d = 1000 | |
| X = [i*xmax/d for i in range(d)] | |
| alp = np.linspace(0, 5, 2000) | |
| for t_eta in [2, 5, 10, 50, 100]: | |
| Z = [] | |
| for alpha in alp: |
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
| def proba_mp(alpha, x, lambda_m, lambda_p): | |
| if x == 0: | |
| return 1-alpha if alpha<1 else 0 | |
| if x<lambda_m or lambda_p<x: | |
| return 0 | |
| return math.sqrt((lambda_p-x) * (x-lambda_m)) / (2*x*math.pi*alpha) | |
| xmax = 5 |
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
| x = Input(shape=(128,128,3)) | |
| n = 16 | |
| y0 = Conv2D(n, (3,3), padding='same', activation='relu')(x) | |
| y0 = Conv2D(n, (3,3), padding='same', activation='relu')(y0) | |
| y0 = Conv2D(n, (3,3), padding='same', activation='relu')(y0) | |
| y1 = MaxPooling2D()(y0) # 64 | |
| y1 = Conv2D(2*n, (3,3), padding='same', activation='relu')(y1) |
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 | |
| data = np.load('texture.npz') | |
| X_train = data['X_train'] | |
| Y_train = data['Y_train'] | |
| X_test = data['X_test'] | |
| Y_test = data['Y_test'] | |
| import cv2 | |
| import matplotlib.pyplot as plt |
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 base64 | |
| def _image_url(img): | |
| retval, buffer = cv2.imencode('.jpg', img) | |
| base64_byte_string = base64.b64encode(buffer).decode('utf-8') | |
| return "data:image/JPEG;base64," + base64_byte_string |
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 IPython.display | |
| def _display_html(html_str): | |
| html = IPython.display.HTML(html_str) | |
| IPython.display.display(html) | |
| def test(): | |
| code = ''' |
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.engine.topology import Layer | |
| class RoiPooling(Layer): | |
| def __init__(self, pool_size, **kwargs): | |
| self.pool_size = pool_size | |
| super(RoiPooling, self).__init__(**kwargs) | |
| def build(self, input_shape): | |
| self.num_channels = input_shape[0][3] | |
| self.num_rois = input_shape[1][1] |
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.models import Sequential, Model | |
| from keras.layers import (Conv2D, Dense, GlobalAveragePooling2D, | |
| BatchNormalization, Activation, Flatten, | |
| Reshape, Input) | |
| x = Input(shape=(140,140,1)) | |
| y = Conv2D(16, (10,10), strides=(10,10), padding='valid')(x) | |
| y = BatchNormalization()(y) | |
| y = Activation('relu')(y) |
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 import backend as K | |
| def my_loss( y_true, y_pred ): | |
| loss_conf, loss_bbox, loss_cls = K.variable(value=0), K.variable(value=0), K.variable(value=0) | |
| for i in range(y_pred.shape[-2]): | |
| true_bbox, true_conf, true_cls = y_true[..., i,:4], y_true[..., i,4], y_true[..., i,5:] | |
| pred_bbox, pred_conf, pred_cls = y_pred[..., i,:4], y_pred[..., i,4], y_pred[..., i,5:] | |
| pred_conf = K.sigmoid(pred_conf) | |
| pred_bbox = K.sigmoid(pred_bbox) |
NewerOlder