Skip to content

Instantly share code, notes, and snippets.

import torch
import torch.nn as nn
from torch.nn import Linear, Conv2d, BatchNorm1d, BatchNorm2d, PReLU, ReLU, Sigmoid, Dropout, MaxPool2d, \
AdaptiveAvgPool2d, Sequential, Module
from collections import namedtuple
# Support: ['IR_50', 'IR_101', 'IR_152', 'IR_SE_50', 'IR_SE_101', 'IR_SE_152']
_, C2, C3, C4, C5 = resnet_graph(input_image, "resnet50", stage5=True)
P5 = KL.Conv2D(256, (1, 1), name='fpn_c5p5')(C5)
P4 = KL.Add(name="fpn_p4add")([
KL.UpSampling2D(size=(2, 2), name="fpn_p5upsampled")(P5),
KL.Conv2D(256, (1, 1), name='fpn_c4p4')(C4)])
P3 = KL.Add(name="fpn_p3add")([
KL.UpSampling2D(size=(2, 2), name="fpn_p4upsampled")(P4),
KL.Conv2D(256, (1, 1), name='fpn_c3p3')(C3)])
P2 = KL.Add(name="fpn_p2add")([
KL.UpSampling2D(size=(2, 2), name="fpn_p3upsampled")(P3),
@John1231983
John1231983 / jaccard_coef_loss.py
Created March 9, 2018 14:34 — forked from wassname/jaccard_coef_loss.py
jaccard_coef_loss for keras. This loss is usefull when you have unbalanced classes within a sample such as segmenting each pixel of an image. For example you are trying to predict if each pixel is cat, dog, or background. You may have 80% background, 10% dog, and 10% cat. Should a model that predicts 100% background be 80% right, or 30%? Categor…
from keras import backend as K
def jaccard_distance_loss(y_true, y_pred, smooth=100):
"""
Jaccard = (|X & Y|)/ (|X|+ |Y| - |X & Y|)
= sum(|A*B|)/(sum(|A|)+sum(|B|)-sum(|A*B|))
The jaccard distance loss is usefull for unbalanced datasets. This has been
shifted so it converges on 0 and is smoothed to avoid exploding or disapearing
gradient.
lee@lee:~$ sudo apt-get dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
apport : Depends: python3-apport (>= 2.20.1-0ubuntu2.14) but 2.20.1-0ubuntu2.13 is installed
apport-gtk : Depends: python3-apport (>= 2.20.1-0ubuntu2.14) but 2.20.1-0ubuntu2.13 is installed
E: Unmet dependencies. Try using -f.
class ResNet_101(object):
def __init__(self, inputs, num_classes, phase):
self.inputs = inputs
self.num_classes = num_classes
self.channel_axis = 3
self.phase = phase # train (True) or test (False), for BN layers in the decoder
self.build_network()
def build_network(self):
self.encoding = self.build_encoder()
/JPEGImages/2007_000033.jpg /SegmentationClassAug/2007_000033.png
/JPEGImages/2007_000042.jpg /SegmentationClassAug/2007_000042.png
/JPEGImages/2007_000061.jpg /SegmentationClassAug/2007_000061.png
/JPEGImages/2007_000123.jpg /SegmentationClassAug/2007_000123.png
/JPEGImages/2007_000129.jpg /SegmentationClassAug/2007_000129.png
/JPEGImages/2007_000175.jpg /SegmentationClassAug/2007_000175.png
/JPEGImages/2007_000187.jpg /SegmentationClassAug/2007_000187.png
/JPEGImages/2007_000323.jpg /SegmentationClassAug/2007_000323.png
/JPEGImages/2007_000332.jpg /SegmentationClassAug/2007_000332.png
/JPEGImages/2007_000346.jpg /SegmentationClassAug/2007_000346.png
/JPEGImages/2007_000032.jpg /SegmentationClassAug/2007_000032.png
/JPEGImages/2007_000039.jpg /SegmentationClassAug/2007_000039.png
/JPEGImages/2007_000063.jpg /SegmentationClassAug/2007_000063.png
/JPEGImages/2007_000068.jpg /SegmentationClassAug/2007_000068.png
/JPEGImages/2007_000121.jpg /SegmentationClassAug/2007_000121.png
/JPEGImages/2007_000170.jpg /SegmentationClassAug/2007_000170.png
/JPEGImages/2007_000241.jpg /SegmentationClassAug/2007_000241.png
/JPEGImages/2007_000243.jpg /SegmentationClassAug/2007_000243.png
/JPEGImages/2007_000250.jpg /SegmentationClassAug/2007_000250.png
/JPEGImages/2007_000256.jpg /SegmentationClassAug/2007_000256.png
import tensorflow as tf
import numpy as np
import os
from PIL import Image
from dir_traversal_tfrecord import tfrecord_auto_traversal
flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_integer("image_number", 186, "Number of images in your tfrecord, default is 186.")
/*
RSI - cykedev 14/02/2014
(updated a couple of times since, check git history)
*/
// helpers
var _ = require('lodash');
var log = require('../core/log.js');
/*
StochRSI - SamThomp 11/06/2014
(updated by askmike) @ 30/07/2016
*/
// helpers
var _ = require('lodash');
var log = require('../core/log.js');