tensorflow

对抗训练和对抗样本

十年热恋 提交于 2021-02-15 11:08:10
对抗训练 分类模型:对已有图片训练模型并分类 生成模型:分类模型的反向过程生成一张图片, 从一个类别向量反向生成一张图片 对抗样本 对图片通过算法增加一些噪声,变成新的图片,新的图片人眼无法分辨出变化,但是机器能分辨出来而且还会判错类别。 目前一些对抗样本生成算法: FGSM、FGMT:基于攻击者设置的对抗目标函数,利用梯度来优化原数据样本feature的值。 JSMA:基于模型输入输出之间的雅可比矩阵(Jacobian)来决定对输出影响最大的输入feature,进而改变这些feature来生成对抗样本。 DeepFool: 目的是寻找可以使分类器产生误判的最小扰动。简单理解就是点到分界面的各个最小距离。 开源项目 cleverhans Tensorflow下的子项目,完成了FGSM、FGMT、deepfool、CW2、JSMA等对抗样本攻击算法,提供tensorflow,keras,pytorch接口支持,可加载预训练模型。 https://github.com/tensorflow/cleverhans.git Foolbox 用来产生对抗样本的python工具箱,支持Pytorch、TensorFlow、Keras https://github.com/bethgelab/foolbox.git AdvBox 百度提供的AI模型安全工具箱,可产生对抗样本 https:/

TensorFlow Estimator ServingInputReceiver features vs receiver_tensors: when and why?

时间秒杀一切 提交于 2021-02-15 10:04:26
问题 In a previous question the purpose and structure of the serving_input_receiver_fn is explored and in the answer: def serving_input_receiver_fn(): """For the sake of the example, let's assume your input to the network will be a 28x28 grayscale image that you'll then preprocess as needed""" input_images = tf.placeholder(dtype=tf.uint8, shape=[None, 28, 28, 1], name='input_images') # here you do all the operations you need on the images before they can be fed to the net (e.g., normalizing,

TensorFlow Estimator ServingInputReceiver features vs receiver_tensors: when and why?

房东的猫 提交于 2021-02-15 10:03:38
问题 In a previous question the purpose and structure of the serving_input_receiver_fn is explored and in the answer: def serving_input_receiver_fn(): """For the sake of the example, let's assume your input to the network will be a 28x28 grayscale image that you'll then preprocess as needed""" input_images = tf.placeholder(dtype=tf.uint8, shape=[None, 28, 28, 1], name='input_images') # here you do all the operations you need on the images before they can be fed to the net (e.g., normalizing,

TensorFlow Estimator ServingInputReceiver features vs receiver_tensors: when and why?

允我心安 提交于 2021-02-15 10:03:16
问题 In a previous question the purpose and structure of the serving_input_receiver_fn is explored and in the answer: def serving_input_receiver_fn(): """For the sake of the example, let's assume your input to the network will be a 28x28 grayscale image that you'll then preprocess as needed""" input_images = tf.placeholder(dtype=tf.uint8, shape=[None, 28, 28, 1], name='input_images') # here you do all the operations you need on the images before they can be fed to the net (e.g., normalizing,

How to get tensorflow-gpu v2 working on Windows with NVidia GPU

落爺英雄遲暮 提交于 2021-02-15 07:39:45
问题 What are the steps to get tensorflow-gpu 2.x Python package working on Windows with an NVidia GPU? I.e. how can I get rid of Could not find 'cudart64_101.dll' and then Could not find 'cudnn64_7.dll' ? 回答1: Steps Requires specific versions according to the error messages you see, not latest versions! 1. Download and install latest NVidia driver https://www.nvidia.com/Download/index.aspx 2. Install Tensorflow Python package pip uninstall tensorflow pip install tensorflow-gpu 3. Test At first

10个算法从业人员必须知道的TensorFlow技巧

独自空忆成欢 提交于 2021-02-15 05:05:46
点击上方“AI公园”,关注公众号,选择加“星标“或“置顶” 作者: Rohan Jag tap 编译:ronghuaiyang 导读 掌握这些可以更高效的模型的提高开发效率。 TensorFlow 2.x在构建模型和TensorFlow的整体使用方面提供了很多简单性。那么TF2有什么新变化呢? 使用Keras轻松构建模型,立即执行。 可在任何平台上进行强大的模型部署。 强大的研究实验。 通过清理过时的API和减少重复来简化API。 在本文中,我们将探索TF 2.0的10个特性,这些特性使得使用TensorFlow更加顺畅,减少了代码行数并提高了效率。 1(a). tf.data 构建输入管道 tf.data提供了数据管道和相关操作的功能。我们可以建立管道,映射预处理函数,洗牌或批处理数据集等等。 从tensors构建管道 >>> dataset = tf.data.Dataset.from_tensor_slices([ 8 , 3 , 0 , 8 , 2 , 1 ]) >>> iter(dataset).next().numpy() 8 构建Batch并打乱 # Shuffle >>> dataset = tf.data.Dataset.from_tensor_slices([ 8 , 3 , 0 , 8 , 2 , 1 ]).shuffle( 6 ) >>> iter

Tensorflow 运行警告提示 Your CPU supports instructions that this TensorFlow binary was not compiled...

天涯浪子 提交于 2021-02-15 03:55:50
由于现在神经网络这个东西比较火,准确的说是深度学习这个东西比较火,我们实验室准备靠这个东西发几个CCF A类的文章,虽然我不太懂这东西,兴趣也一般都是毕竟要跟随主流的,于是今天安装起了 Tensorflow 这个深度学习的框架。 安装好以后运行一个Demo ,如下: import tensorflow as tf a =tf.constant(2 ) b =tf.constant(20 ) with tf.Session() as sess: print (sess.run(a*b)) 运行结果如下: 2018-05-03 19:57:44.151803: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA 2018-05-03 19:57:44.251905: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] successful NUMA node read from SysFS had negative value (-1), but

RaggedTensor request to TensorFlow serving fails

旧时模样 提交于 2021-02-15 02:46:22
问题 I've created a TensorFlow model that uses RaggedTensors. Model works fine and when calling model.predict and I get the expected results. input = tf.ragged.constant([[[-0.9984272718429565, -0.9422321319580078, -0.27657580375671387, -3.185823678970337, -0.6360141634941101, -1.6579184532165527, -1.9000954627990723, -0.49169546365737915, -0.6758883595466614, -0.6677696704864502, -0.532067060470581], [-0.9984272718429565, -0.9421600103378296, 2.2048349380493164, -1.273996114730835, -0

风格迁移算法

非 Y 不嫁゛ 提交于 2021-02-14 10:04:09
最近推导了一些机器学习入门的算法,老是搞那些数学知识,搞的自己都没信心和新区了。今天学着玩点有趣好玩的。 图像的艺术风格迁移算法,算是一个简单有趣,而且一般人都能看得到效果的算法。图像艺术风格迁移,简单的理解,就是找一个照片作为内容,然后把这个照片换成梵高或者毕加索等制定的风格。关于 图像艺术风格迁移 的一些历史和知识,大家可以看看这篇文章: 图像风格迁移(Neural Style)简史 。 思路 风格迁移的大概思路是:我们需要准备两张图片。一张是我们将要输出的内容图片,另外一张是我们需要模仿的风格图片。我们需要输出一张图片,让输出的这张图片的内容和内容图片相近,让输出图片的风格和风格图片的风格相近。 <br /> 内容最接近的算法 内容最接近,相对来说比较简单。简单的理解可以对比每个图片的像素,然后计算他们的差距。也可以是计算CNN中间某个卷积层得到的特征值之间的距离。 <br /> 我经过调试发现,如果内容图层取得太靠前,效果不太好。因为内容特征越靠前,相当于对比的越细腻,而风格迁移要得到的效果是宏观上更像内容图片,细节上用风格表现,这样效果最好。 风格最接近的算法 风格的比较是最难理解的。要理解风格比较的算法,需要了解一个名词叫做格拉姆矩阵。听常博士说这个知识属于矩阵分析里面的内容。我对这方面没系统学习过,不太懂。但是我能理解到的层次是:你给定N个卷积核,然后可以得到N个矩阵

Keras: .predict returns percentages instead of classes

拜拜、爱过 提交于 2021-02-13 17:41:12
问题 I am building a model with 3 classes: [0,1,2] After training, the .predict function returns a list of percentages instead. I was checking the keras documentation but could not figure out, what I did wrong. .predict_classes is not working anymore, and I did not have this problem with previous classifiers. I already tried different activation functions (relu, sigmoid etc.) If I understand correctly, the number in Dense(3...) defines the amount of classes. outputs1=Dense(3,activation='softmax')