tensor

WGAN-GP精彩分析(附源代码)

匆匆过客 提交于 2019-12-05 10:54:02
转载自: https://www.e-learn.cn/content/qita/814071 from datetime import datetime import os import matplotlib.pyplot as plt import numpy as np import tensorflow as tf from six.moves import xrange data = np.load('final37.npy') data = data[:,:,0:60] #显示原始数据图像 def Show_images(data,show_nums,save=False): index = 0 for n in range(show_nums): show_images = data[index:index+100] show_images = show_images.reshape(100,3,60,1) r,c = 10,10 fig,axs = plt.subplots(r,c) cnt = 0 for i in range(r): for j in range(c): xy = show_images[cnt] for k in range(len(xy)): x = xy[k][0:30] y = xy[k][30:60] if k == 0 : axs[i

PyTorch教程001

房东的猫 提交于 2019-12-05 09:46:05
第一节 基本的操作 点我,所有内容翻译于此链接 什么是PyTorch? 它是基于Python语言的科学计算工具包,其设计目的包括以下两个方面: 替代Numpy从而可以使用强大的GPU进行计算 一个深读学习的研究平台,致力于提供最大的灵活性与速度 我们开始吧~ Tensors Tensors和Numpy的ndarrays很像,与之不同之处在于Tensor可以在GPU上进行运算从而获得更快的计算速度。 from __future__ import print_function import torch 利用pyTorch构造一个未初始化的5×3的矩阵: x = torch.Tensor( 5 , 3 ) print(x) -9.3921e+17 4.5628e-41 -9.3921e+17 4.5628e-41 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 [torch.FloatTensor of size 5x3] 类似于上一步,构造一个随机(值域为[0,1])初始化的矩阵: x = torch.rand( 5 , 3 ) print(x) 0.9144 0.5597 0.7737 0

TensorFlow :HelloWorld

北慕城南 提交于 2019-12-05 09:22:03
1、TensorFlow简介 >使用计算图 (graph) 来表示计算任务. >在被称之为会话 (Session) 的上下文 (context) 中执行图. >使用 tensor 表示数据. >通过变量 (Variable) 维护状态. >使用feed和fetch可以为任意的操作(arbitrary operation) 赋值或者从其中获取数据. TensorFlow 是一个编程系统, 使用图来表示计算任务. 图中的节点被称之为 op (operation 的缩写). 一个 op 获得 0 个或多个 Tensor, 执行计算, 产生 0 个或多个 Tensor. 每个 Tensor 是一个类型化的多维数组. 例如, 你可以将一小组图像集表示为一个四维浮点数数组, 这四个维度分别是 [batch, height, width, channels]. 一个 TensorFlow 图描述了计算的过程. 为了进行计算, 图必须在 会话 里被启动. 会话 将图的 op 分发到诸如 CPU 或 GPU 之类的 设备 上, 同时提供执行 op 的方法. 这些方法执行后, 将产生的 tensor 返回. 在 Python 语言中, 返回的 tensor 是 numpy ndarray 对象; 在 C 和 C++ 语言中, 返回的 tensor 是 tensorflow::Tensor 实例. 2

tensorflow源码分析(二)

房东的猫 提交于 2019-12-05 09:15:06
2015年11月9日,Google发布深度学习框架TensorFlow并宣布开源,并迅速得到广泛关注,在图形分类、音频处理、推荐系统和自然语言处理等场景下都被大面积推广。TensorFlow系统更新快速,官方文档教程齐全,上手快速且简单易用,支持Python和C++接口。本文依据对Tensorflow(简称TF)白皮书 [1] 、TF Github [2] 和TF官方教程 [3] 的理解,从系统和代码实现角度讲解TF的内部实现原理。以Tensorflow r0.8.0为基础,本文由浅入深的阐述Tensor和Flow的概念。先介绍了TensorFlow的核心概念和基本概述,然后剖析了OpKernels模块、Graph模块、Session模块。 1. TF系统架构 1.1 TF依赖视图 TF的依赖视图如图1所示 [4] ,描述了TF的上下游关系链。 图 1 TensorFlow依赖视图 TF托管在github平台,有google groups和contributors共同维护。 TF提供了丰富的深度学习相关的API,支持Python和C/C++接口。 TF提供了可视化分析工具Tensorboard,方便分析和调整模型。 TF支持Linux平台,Windows平台,Mac平台,甚至手机移动设备等各种平台。 1.2 TF系统架构 图2是TF的系统架构,从底向上分为设备管理和通信层

DCGAN及其tensorflow版源码解读

冷暖自知 提交于 2019-12-05 09:11:53
上一节我们提到 G 和 D 由多层感知机定义 。 深度学习中对图像处理应用最好的模型是 CNN ,那么如何把 CNN 与 GAN 结合? DCGAN 是这方面最好的尝试之一。 源码: https://github.com/Newmu/dcgan_code 。DCGAN论文作者用theano实现的,他还放上了其他人实现的版本,本文主要讨论tensorflow版本。 TensorFlow 版本的源码: https://github.com/carpedm20/DCGAN-tensorflow DCGAN把上述的G和D换成了两个卷积神经网络(CNN)。但不是直接换就可以了,DCGAN对卷积神经网络的结构做了一些改变,以提高样本的质量和收敛的速度,这些改变有: 取消所有pooling层。G网络中使用转置卷积(transposed convolutional layer)进行上采样,D网络中用加入strided的卷积代替pooling。 在D和G中均使用batch normalization 去掉FC层,使网络变为全卷积网络 G网络中使用ReLU作为激活函数,最后一层使用tanh D网络中使用LeakyReLU作为激活函数 这些改变在代码中都可以看到。DCGAN论文中提到对CNN结构有三点重要的改变: (1) Allconvolutional net (Springenberg et al.

TensorFlow 学习笔记

五迷三道 提交于 2019-12-05 08:48:05
TensorFlow是一个Google开源的深度学习框架。Tensor(张量)意味着N维数组,Flow(流)意味着基于数据流图的计算,TensorFlow为张量从流图的一端流动到另一端计算过程。TensorFlow是将复杂的数据结构传输至人工智能神经网中进行分析和处理过程的系统。以下内容是基于Udacity深度学习课程的学习笔记。 安装TensorFlow 利用Conda来安装TensorFlow,需要安装一个TensorFlow环境和所需要的包。 OSX或Linux conda create -n tensorflow python = 3.5 source activate tensorflow conda install pandas matplotlib jupyter notebook scipy scikit -learn conda install -c conda -forge tensorflow Windows conda create -n tensorflow python = 3.5 activate tensorflow conda install pandas matplotlib jupyter notebook scipy scikit -learn conda install -c conda -forge tensorflow

DCGAN实战

谁都会走 提交于 2019-12-05 08:28:17
建立神经网络 我们将通过部署以下函数来建立GANs的主要部分 model_input discirminator generator model_loss model_opt train Input def model_inputs(image_width, image_height, image_channels, z_dim): """ Create the model inputs :param image_width: The input image width :param image_height: The input image height :param image_channels: The number of image channels :param z_dim: The dimension of Z :return: Tuple of (tensor of real input images, tensor of z data, learning rate) """ # TODO: Implement Function input_real = tf.placeholder(tf.float32, [None,image_width,image_height,image_channels],name = 'input_real') input_z=tf

How to apply a custom function to specific columns in a matrix in PyTorch

人盡茶涼 提交于 2019-12-05 07:55:21
I have a tensor of size [150, 182, 91], the first part is just the batch size while the matrix I am interested in is the 182x91 one. I need to run a function on the 182x91 matrix for each of the 50 dimensions separately. I need to get a diagonal matrix stripe of the 182x91 matrix, and the function I am using is the following one (based on my previous question: Getting diagonal matrix stripe automatically in numpy or pytorch ): def stripe(a): i, j = a.size() assert (i >= j) out = torch.zeros((i - j + 1, j)) for diag in range(0, i - j + 1): out[diag] = torch.diag(a, -diag) return out The stripe

从mnist看tensorflow运行方式

不打扰是莪最后的温柔 提交于 2019-12-05 07:50:22
目录 目录 tensorflow是如何运行的 有向图 会话 Tensor 变量与常量 用fetches取出数据用feeds输入数据 tensorflow是如何运行的: 将计算流程表示成图 通过sessions执行图的计算 数据表示为张量(tensors) 用Variables表示状态(如权重) 分别使用feeds和fetches来填充和取出数据 有向图: tensorflow的计算是由图表示的。下面是一个mnist例子改编的例子,用于展示tensorflow的有向图定义,也用于展示tensorboard的用法。 节点:节点如layer1,cross_entropy代表的是运算,input也可以看做是输入操作 有向箭头表示数据的流向 从图中可以看出,输入数据之后,可以通过tf.reshape()函数对于输入的张量进行reshape;也可以构造一个网络:网络第一层:layer1, drop_out层,第二层:layer2,然后计算交叉熵(利用input,layer2的数据),计算准确率(利用input,layer2)。我们获得了除每一层维度之外所有有关计算的信息。 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data max_steps = 1000 learning

不加班的秘诀:如何通过AOE快速集成NCNN?

偶尔善良 提交于 2019-12-05 06:39:26
作为我司头发储量前三的 程序员 始终仗着头发多奋斗在加班的第一线 时时灵魂拷问自己 年轻人,你凭什么不加班? 虽然我没有女朋友 但是,我有代码呀 但我不明白的是,隔壁工位那个,到岗比我迟,下班比我早,天天准点儿下班接女朋友,工作还完成的不错的样子,当然,头发也还不错。除了长得比我显老,难道他有什么制胜法宝吗?趁着午休,以一礼拜咖啡为代价,我偷师了他的制胜法宝。GET了秘诀,或许我也可以事业爱情双丰收了。 直接集成NCNN的缺点 直接集成NCNN熬老少男颜哇,想当年我一边泪流满面地集成,一边想用女友的SK2给自己的脸补补 (不,你没有, both SK2和女友) , 咋回事儿呢,为SqueezeNet接入NCNN,把相关的模型文件,NCNN的头文件和库,JNI调用,前处理和后处理相关业务逻辑等。把这些内容都放在SqueezeNet Sample工程里。这样简单直接的集成方法,问题也很明显,和业务耦合比较多,不具有通用性,前处理后处理都和SqueezeNcnn这个Sample有关,不能很方便地提供给其他业务组件使用。深入思考一下,如果我们把AI业务,作为一个一个单独的AI组件提供给业务的同学使用,会发生这样的情况: 每个组件都要依赖和包含NCNN的库,而且每个组件的开发同学,都要去熟悉NCNN的接口,写C的调用代码,写JNI。所以我们很自然地会想到要提取一个NCNN的组件出来