Skip to content

Instantly share code, notes, and snippets.

View mkocabas's full-sized avatar

Muhammed Kocabas mkocabas

View GitHub Profile
@mkocabas
mkocabas / training.py
Last active December 15, 2017 13:12
Pose grammar training
import numpy as np
from pycocotools.coco import COCO
import os
import math
import keras
from keras.models import Model
from keras.layers import Dense, Input, Flatten, Reshape
from keras.utils import plot_model
from random import shuffle
name: "1546"
layer {
name: "data"
type: "ImageSegData"
top: "data"
top: "label"
#top: "data_dim"
include {
phase: TRAIN
from keras.optimizers import Optimizer
from keras import backend as K
from keras.legacy import interfaces
class MultiSGD(Optimizer):
"""
Modified SGD with added support for learning multiplier for kernels and biases
as suggested in: https://github.com/fchollet/keras/issues/5920
def focal_loss(gamma=2, alpha=0.75):
def focal_loss_fixed(y_true, y_pred): # compatible with tf backend
pt_1 = tf.where(tf.equal(y_true, 1), y_pred, tf.ones_like(y_pred))
pt_0 = tf.where(tf.equal(y_true, 0), y_pred, tf.zeros_like(y_pred))
return -K.sum(alpha * K.pow(1. - pt_1, gamma) * K.log(pt_1))-K.sum((1-alpha) * K.pow( pt_0, gamma) * K.log(1. - pt_0))
return focal_loss_fixed
tb = TensorBoard(
log_dir='./logs/{}'.format(args.exp_dir),
histogram_freq=0,
batch_size=args.batch_size,
write_graph=True,
write_batch_performance=True,
write_grads=False,
write_images=False,
embeddings_freq=0,
embeddings_layer_names=None,
# coding: utf-8
# In[ ]:
"""
Copyright (c) 2017, by the Authors: Amir H. Abdi
This software is freely available under the MIT Public License.
Please see the License file in the root for details.
from mininet.net import Mininet
from random import randint
from scipy import spatial
import numpy as np
import scipy as scp
import math
## Mininet must run as ROOT !!!
# add function for nodes to move randomly when invoked
####################### retinanet.py
def default_null_model(
pyramid_feature_size=256,
name='null_submodel'
):
options = {
'kernel_size' : 3,
'strides' : 1,
'padding' : 'same',
}
from __future__ import print_function, absolute_import
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as models
class FPN(nn.Module):
def __init__(self,
backbone='resnet50',
import torch
import torch.nn.functional as F
from torch.nn.parameter import Parameter
import numpy as np
class SpatialSoftmax(torch.nn.Module):
def __init__(self, height, width, channel, temperature=None, data_format='NCHW', unnorm=False):
super(SpatialSoftmax, self).__init__()
self.data_format = data_format