keras

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

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

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')

Keras: .predict returns percentages instead of classes

时光总嘲笑我的痴心妄想 提交于 2021-02-13 17:39:23
问题 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')

Keras: .predict returns percentages instead of classes

筅森魡賤 提交于 2021-02-13 17:38:59
问题 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')

Save keras model as .h5

余生长醉 提交于 2021-02-12 11:38:53
问题 I want to save my trained keras model as .h5 file. Should be straight forward. Short example: #%% import tensorflow as tf import numpy as np from tensorflow.keras.callbacks import ModelCheckpoint import matplotlib.pyplot as plt print('TF version: ',tf.__version__) #%% ######################### # BATCH SIZE BATCH_SIZE=100 ######################## # create training data X_train_set = np.random.random(size=(10000,10)) y_train_set = np.random.random(size=(10000)) # create validation data X_val

AttributeError: module 'tensorflow.python.framework.ops' has no attribute 'RegisterShape'

萝らか妹 提交于 2021-02-11 17:41:54
问题 I am using TensorFlow 2.1.0-dev20191125 Unfortunately I can't compile a simple example with error: "AttributeError: module 'tensorflow.python.framework.ops' has no attribute 'RegisterShape'" My source code: from tensorflow.python.framework import ops as _ops _ops.RegisterShape("GRUBlockCell")(None) Is it looks like incorrectly installed TF ? 回答1: Shape functions for core ops were moved to C++ via REGISTER_OP(...).SetShapeFn(...) . So you may have to first create/register your operation in C++

“TypeError: 'Session' object is not callable” error running sess = tf.compat.v1.Session()(graph=tf.compat.v1.get_default_graph(), config=session_conf)

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-11 17:37:20
问题 I'm trying to set seeds and configure keras settings to ensure my experiments are reproducible. When I run the following (based on code in an answer to this question): # Import libraries import numpy as np import pandas as pd import tensorflow as tf from tensorflow.keras.models import load_model from tensorflow.keras.regularizers import l2 # for setting seeds and configuring keras so that experiments are reproducible from numpy.random import seed import random as rn import os from tensorflow

“TypeError: 'Session' object is not callable” error running sess = tf.compat.v1.Session()(graph=tf.compat.v1.get_default_graph(), config=session_conf)

一世执手 提交于 2021-02-11 17:37:20
问题 I'm trying to set seeds and configure keras settings to ensure my experiments are reproducible. When I run the following (based on code in an answer to this question): # Import libraries import numpy as np import pandas as pd import tensorflow as tf from tensorflow.keras.models import load_model from tensorflow.keras.regularizers import l2 # for setting seeds and configuring keras so that experiments are reproducible from numpy.random import seed import random as rn import os from tensorflow

Why Tensorflow results are different in Python versions 3.5 and 3.7

雨燕双飞 提交于 2021-02-11 15:58:58
问题 Why Tensorflow results are different in Python versions 3.5 (SQL server, machine learning services) and 3.7 (local machine, anaconda)? I found out, it depends on 4 parameters values: dataset size number of epochs number of 1st layer (input) neurons number of 2nd layer (hidden) neurons Here is the example: identical results: dataset size - 50 000 number of epochs - 5/3/2 number of 1st layer (input) neurons - 300 **number of 2nd layer (hidden) neurons - 80% from 1st layer** different results: