资源简介
keras 官方例子,深度学习专用,机器学习专用,代码简单,
代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Train an Auxiliary Classifier Generative Adversarial Network (ACGAN) on the
MNIST dataset. See https://arxiv.org/abs/1610.09585 for more details.
You should start to see reasonable images after ~5 epochs and good images
by ~15 epochs. You should use a GPU as the convolution-heavy operations are
very slow on the CPU. Prefer the TensorFlow backend if you plan on iterating
as the compilation time can be a blocker using Theano.
Timings:
Hardware | Backend | Time / Epoch
-------------------------------------------
CPU | TF | 3 hrs
Titan X (maxwell) | TF | 4 min
Titan X (maxwell) | TH | 7 min
Consult https://github.com/lukedeo/keras-acgan for more information and
example output
“““
from __future__ import print_function
from collections import defaultdict
try:
import cPickle as pickle
except ImportError:
import pickle
from PIL import Image
from six.moves import range
from keras.datasets import mnist
from keras import layers
from keras.layers import Input Dense Reshape Flatten embedding Dropout
from keras.layers import BatchNormalization
from keras.layers.advanced_activations import LeakyReLU
from keras.layers.convolutional import Conv2DTranspose Conv2D
from keras.models import Sequential Model
from keras.optimizers import Adam
from keras.utils.generic_utils import Progbar
import numpy as np
np.random.seed(1337)
num_classes = 10
def build_generator(latent_size):
# we will map a pair of (z L) where z is a latent vector and L is a
# label drawn from P_c to image space (... 28 28 1)
cnn = Sequential()
cnn.add(Dense(3 * 3 * 384 input_dim=latent_size activation=‘relu‘))
cnn.add(Reshape((3 3 384)))
# upsample to (7 7 ...)
cnn.add(Conv2DTranspose(192 5 strides=1 padding=‘valid‘
activation=‘relu‘
kernel_initializer=‘glorot_normal‘))
cnn.add(BatchNormalization())
# upsample to (14 14 ...)
cnn.add(Conv2DTranspose(96 5 strides=2 padding=‘same‘
activation=‘relu‘
kernel_initializer=‘glorot_normal‘))
cnn.add(BatchNormalization())
# upsample to (28 28 ...)
cnn.add(Conv2DTranspose(1 5 strides=2 padding=‘same‘
activation=‘tanh‘
kernel_initializer=‘glorot_normal‘))
# this is the z space commonly referred to in GAN papers
latent = Input(shape=(latent_size ))
# this will be our label
image_class = Input(shape=(1) dtype=‘int32‘)
cls = Flatten()(embedding(num_classes latent_size
embeddings_initializer=‘glorot_normal‘)(image_class))
# hadamard product between z-space and a class conditional embedding
h = layers.multiply([latent cls])
fake_image = cnn(h)
return Model([latent image_class] fake_image)
def build_discriminator():
# build a relatively
- 上一篇:Pubfig人脸数据库多线程命名器
- 下一篇:densenet121.py
相关资源
- densenet121.py
- 集成k-最近邻(k-NN)、朴素贝叶斯、
- Python-机器学习完全课程
- Python-Glyce用于汉字表示的字形向量
- 燕大《Python机器学习》实验报告 .do
- 卷积神经网络轴承数故障分类
- python实现谱聚类代码并进行可视化
- 机器学习-python处理UCI鲍鱼数据集.ra
- 利用贝叶斯算法实现垃圾邮件分类
- 利用鸢尾花数据集画出P-R曲线 pytho
- 实战python利用线性回归来预测鲍鱼年
- 实战python线性回归
- python图像裁剪
- 使用训练好的模型进行预测
- Python→Transorflow猫狗识别完整代码,附
- Python Keras库 安装包
- FaceClustering.zip
- Python-RNNoiseRNN音频噪声抑制学习
- Python-Keras实现实时语义分割的深层神
- Python-手势识别使用在TensorFlow中卷积神
- python 机器学习之支持向量机非线性回
- datingTestSet2.txt
- 多层BP神经网络参数高自由度Python
- 目标检测自动标注代码
- 利用keras实现的cnn卷积神经网络对手写
- 梯度下降python程序实现+可视化
- 基于深度学习的表情识别系统
- 语义分割标注转为目标检测框标注
- keras上LSTM长短期记忆网络金融时序预
- 二项分布的代码可视化实现
评论
共有 条评论