Skip to content

Instantly share code, notes, and snippets.

@t-ae
t-ae / main.swift
Last active July 23, 2019 07:39
VAE on Swift for TensorFlow
// VAE by modifying official autoencoder code
// https://github.com/tensorflow/swift-models/blob/2fa11ba1d28ef09454af9da77e22b585cf3e5b7b/Autoencoder/main.swift
// Copyright 2019 The TensorFlow Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
struct Kollection<T> {
var array: Array<T>
let indices: [Int]
subscript(indice: Int) -> T {
get {
precondition(indices.contains(indice))
return array[indice]
}
set {
@t-ae
t-ae / minibatch_discrimination_pytorch.py
Created August 8, 2017 13:48
Minibatch discrimination module in PyTorch
import torch
import torch.nn as nn
import torch.nn.init as init
class MinibatchDiscrimination(nn.Module):
def __init__(self, in_features, out_features, kernel_dims, mean=False):
super().__init__()
self.in_features = in_features
self.out_features = out_features
self.kernel_dims = kernel_dims
import tensorflow as tf
from keras import backend as K
config = tf.ConfigProto()
config.gpu_options.allow_growth=True
sess = tf.Session(config=config)
K.set_session(sess)
#!/usr/bin/env python
import numpy as np
from keras.models import Sequential
from keras.layers import InputLayer, Reshape, Flatten, Dense
from keras.layers.convolutional import Conv2D, MaxPooling2D, Conv2DTranspose
from keras.layers.normalization import BatchNormalization
from keras.layers.advanced_activations import ELU
from keras.datasets import cifar10
from keras.optimizers import Adam
#!/usr/bin/env python
import numpy as np
from keras.models import Sequential
from keras.layers import InputLayer
from keras.backend import image_dim_ordering, set_image_dim_ordering
from pixel_shuffler import PixelShuffler
batch_size = 6
in_height = 4
@t-ae
t-ae / pixel_shuffler.py
Last active January 23, 2024 02:02
PixelShuffler layer for Keras
"""
The MIT License (MIT)
Copyright (c) 2018 Takehiro Araki.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@t-ae
t-ae / trainable_test.py
Created November 18, 2016 16:42
trainable_test.py
#!/usr/bin/env python
from keras.models import Sequential
from keras.layers import Dense
import numpy as np
def set_trainable(model, trainable):
model.trainable = trainable
for layer in model.layers:
layer.trainable = trainable