tensorflow

Why is TF Keras inference way slower than Numpy operations?

心已入冬 提交于 2020-12-28 16:29:35
问题 I'm working on a reinforcement learning model implemented with Keras and Tensorflow. I have to do frequent calls to model.predict() on single inputs. While testing inference on a simple pretrained model, I noticed that using Keras' model.predict is WAY slower than just using Numpy on stored weights. Why is it that slow and how can I accelerate it? Using pure Numpy is not viable for complex models. import timeit import numpy as np from tensorflow.python.keras.models import Sequential from

Why is TF Keras inference way slower than Numpy operations?

好久不见. 提交于 2020-12-28 16:25:09
问题 I'm working on a reinforcement learning model implemented with Keras and Tensorflow. I have to do frequent calls to model.predict() on single inputs. While testing inference on a simple pretrained model, I noticed that using Keras' model.predict is WAY slower than just using Numpy on stored weights. Why is it that slow and how can I accelerate it? Using pure Numpy is not viable for complex models. import timeit import numpy as np from tensorflow.python.keras.models import Sequential from

全了!从Python入门到入魔

天涯浪子 提交于 2020-12-27 10:12:28
总被读者问到,我看完了python入门的书,后面就不知道要学什么了。今天就给你们整理全套入门到进阶的教程。 这套教程非常全面而且详细,从 Python入门 到 Python进阶 、 Django 、 Flask等Web框架以及爬虫、数据库、算法与数据结构 等方面均有涉及,几乎覆盖了Python 基础及进阶的方方面面。 让你学完之后能独立完成一个完整的项目。 简明Python入门教程 Python进阶教程 Django入门与实践 用 Flask 从零开始搭建网站 Linux操作系统 HTTP入门指南 MySQL数据库面试汇总 520道LeetCode算法刷题 245道Python面试题 现在以上全套教程和思维导图均可免费获取。 如何获取? 1. 识别并关注公众号「 秦子帅 」; 2. 在下面公众号后台回复关键字「 教程 」。 👆 长按上方二维码 2 秒 回复「 教程 」即可获取资料 额外福利 今天给大家分享一份 11 月刚刚出炉的《TensorFlow 2.0 深度学习算法实战》中文版教材。 所有的项目都是 基于TensorFlow 2.0实战。 获取方法 《TensorFlow 2.0 深度学习算法实战》中文版教材电子版 pdf 已经打包好,获取步骤如下: 1. 扫描下方二维码 2. 后台回复关键词: TF2 👆长按上方二维码 2 秒 回复「 TF2 」即可获取资料

Convert Tensorflow model to Caffe model

|▌冷眼眸甩不掉的悲伤 提交于 2020-12-27 08:47:38
问题 I would like to be able to convert a Tensorflow model to Caffe model. I searched on google but I was able to find only converters from caffe to tensorflow but not the opposite. Does anyone have an idea on how to do it? Thanks, Evi 回答1: I've had the same problem and found a solution. The code can be found here (https://github.com/lFatality/tensorflow2caffe) and I've also documented the code in some Youtube videos. Part 1 covers the creation of the architecture of VGG-19 in Caffe and tflearn

How to resolve the error “cannot import name 'string_int_label_map_pb2' from 'object_detection.protos'”

ⅰ亾dé卋堺 提交于 2020-12-27 07:23:54
问题 My friends and I are partaking in a hackathon and are stuck on this one tutorial on training an object detection model: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html But after three people have tried to follow the above tutorial to the letter, we are all stuck on the creating TfRecord step: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html#create-tensorflow-records We get the error message: ImportError: cannot

How to resolve the error “cannot import name 'string_int_label_map_pb2' from 'object_detection.protos'”

被刻印的时光 ゝ 提交于 2020-12-27 07:23:32
问题 My friends and I are partaking in a hackathon and are stuck on this one tutorial on training an object detection model: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html But after three people have tried to follow the above tutorial to the letter, we are all stuck on the creating TfRecord step: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/training.html#create-tensorflow-records We get the error message: ImportError: cannot

tensorflow框架基础之优化(二)

北慕城南 提交于 2020-12-26 14:58:57
防止过拟合 当神经网络得到的是一个过拟合模型时,这个模型基本是没什么应用价值的,因为它的泛化性能非常不好( 泛化即是,机器学习模型学习到的概念在它处于学习的过程中时模型没有遇见过的样本时候的表现,简单理解为预测能力 ),对一些”异常”数据过分的估计,而忽视了问题的整体规律。 为避免过拟合,常采用的方式是添加正则化项,正则化 通过限制权重大小,使得模型不能任意拟合训练数据中的随机噪声 。一般有两种正则化方式: L1正则化 R ( w ) = ∥ w ∥ 1 = ∑ i | w i | L2正则化 R ( w ) = ∥ w ∥ 2 2 = ∑ i | w i | 2 两种方式的区别参考 L1、L2范数的比较 当然,正则化也可以是多种方式的组合,如 R ( w ) = ∑ i α | w i | + ( 1 − α ) w 2 i 所以,损失函数转换成 J ( θ ) + λ R ( w ) ,在tensorflow中实现正则项 weights = tf.constant([[ 1 , 2 ],[ 3 , 4 ]]) lambda = 0.2 # L1范数,regu=(|1|+|2|+|3|+|4|)*0.2 regu1 = tf.contrib.layers.l1_regularizer( lambda )(weights) # L2范数(TF会将L2的结果除2,使得求导的结果更简洁

Getting TypeError: can't pickle _thread.RLock objects

泪湿孤枕 提交于 2020-12-26 09:09:11
问题 Read a number of similar questions, most of them mentioned that you shouldn't try to serialize an unserializable object. I am not able to understand the issue. I am able to save the model as .h5 file but that doesn't serve the purpose of what I am trying to do. Please Help! def image_generator(train_data_dir, test_data_dir): train_datagen = ImageDataGenerator(rescale=1/255, rotation_range = 30, zoom_range = 0.2, width_shift_range=0.1, height_shift_range=0.1, validation_split = 0.15) test

Getting TypeError: can't pickle _thread.RLock objects

人走茶凉 提交于 2020-12-26 09:07:02
问题 Read a number of similar questions, most of them mentioned that you shouldn't try to serialize an unserializable object. I am not able to understand the issue. I am able to save the model as .h5 file but that doesn't serve the purpose of what I am trying to do. Please Help! def image_generator(train_data_dir, test_data_dir): train_datagen = ImageDataGenerator(rescale=1/255, rotation_range = 30, zoom_range = 0.2, width_shift_range=0.1, height_shift_range=0.1, validation_split = 0.15) test

Why are variables defined with 'self' automatically given a ListWrapper() while inheriting from tf.keras.Model?

我的未来我决定 提交于 2020-12-26 04:04:08
问题 I am not familiar with ListWrapper() , but it is being applied to all list variables created with self when my class inherits from tf.keras.Model . https://www.tensorflow.org/api_docs/python/tf/keras/models/Model This is bad because it is causing an IndexError when I use it in certain functions, or even by just passing it through my Tensorflow model. (I am using eager execution) A small reproduction of the problem can be seen with this code: import tensorflow as tf class my_class(tf.keras