我有个问题,我不能用Keras和sorflow重现我的结果。在

似乎最近在Keras documentation site上发布了一个解决这个问题的方法,但不知怎么的它对我不起作用。在

我做错什么了?在

我正在用一个Jupyter笔记本电脑在MBP视网膜上(没有Nvidia GPU)。在# ** Workaround from Keras Documentation **

import numpy as np

import tensorflow as tf

import random as rn

# The below is necessary in Python 3.2.3 onwards to

# have reproducible behavior for certain hash-based operations.

# See these references for further details:

# https://docs.python.org/3.4/using/cmdline.html#envvar-PYTHONHASHSEED

# https://github.com/fchollet/keras/issues/2280#issuecomment-306959926

import os

os.environ['PYTHONHASHSEED'] = '0'

# The below is necessary for starting Numpy generated random numbers

# in a well-defined initial state.

np.random.seed(42)

# The below is necessary for starting core Python generated random numbers

# in a well-defined state.

rn.seed(12345)

# Force TensorFlow to use single thread.

# Multiple threads are a potential source of

# non-reproducible results.

# For further details, see: https://stackoverflow.com/questions/42022950/which-seeds-have-to-be-set-where-to-realize-100-reproducibility-of-training-res

session_conf = tf.ConfigProto(intra_op_parallelism_threads=1, inter_op_parallelism_threads=1)

from keras import backend as K

# The below tf.set_random_seed() will make random number generation

# in the TensorFlow backend have a well-defined initial state.

# For further details, see: https://www.tensorflow.org/api_docs/python/tf/set_random_seed

tf.set_random_seed(1234)

sess = tf.Session(graph=tf.get_default_graph(), config=session_conf)

K.set_session(sess)

# ** Workaround end **

# ** Start of my code **

# LSTM and CNN for sequence classification in the IMDB dataset

from keras.models import Sequential

from keras.layers import Dense

from keras.layers import LSTM

from keras.layers.embeddings import Embedding

from keras.preprocessing import sequence

from sklearn import metrics

# fix random seed for reproducibility

#np.random.seed(7)

# ... importing data and so on ...

# create the model

embedding_vecor_length = 32

neurons = 91

epochs = 1

model = Sequential()

model.add(Embedding(top_words, embedding_vecor_length, input_length=max_review_length))

model.add(LSTM(neurons))

model.add(Dense(1, activation='sigmoid'))

model.compile(loss='mean_squared_logarithmic_error', optimizer='adam', metrics=['accuracy'])

print(model.summary())

model.fit(X_train, y_train, epochs=epochs, batch_size=64)

# Final evaluation of the model

scores = model.evaluate(X_test, y_test, verbose=0)

print("Accuracy: %.2f%%" % (scores[1]*100))

使用的Python版本:

^{pr2}$

解决方法已经包含在代码中(没有效果)。在

每次我做训练的时候,我都会得到不同的结果。在

重置Jupyter笔记本的内核时,第一次与第一次相对应,第二次与第二次相对应。在

所以在重置之后,我总是在第一次运行时得到0.7782,在第二次运行时得到0.7732等等

但是每次运行时,没有内核重置的结果总是不同的。在

任何建议我都会很有帮助的!在

python3.7 keras和tensorflow兼容_结果无法在Python中用Keras和TensorFlow重现相关推荐

  1. python3.7 keras和tensorflow兼容_解决Keras 与 Tensorflow 版本之间的兼容性问题

    在利用Keras进行实验的时候,后端为Tensorflow,出现了以下问题: 1. 服务器端激活Anaconda环境跑程序时,实验结果很差. 环境:tensorflow 1.4.0,keras 2.1 ...

  2. python3 x完全兼容_中国大学MOOC: Python 3.x 系列版本代码完全兼容 Python 2.x系列的既有语法。...

    中国大学MOOC: Python 3.x 系列版本代码完全兼容 Python 2.x系列的既有语法. 答:错 业务流程改造后组织的特征是 答:组织扁平化 提高经济效益 提高组织效率 能更快地为顾客服务 ...

  3. tensorflow图形识别_手把手教你使用TF服务将TensorFlow模型部署到生产环境

    摘要: 训练好的模型不知道如何布置到生产环境?快来学习一下吧! 介绍 将机器学习(ML)模型应用于生产环境已成为一个火热的的话题,许多框架提供了旨在解决此问题的不同解决方案.为解决这一问题,谷歌发布了 ...

  4. tensorflow玻尔兹曼机_资源 | 10种深度学习算法的TensorFlow实现

    原标题:资源 | 10种深度学习算法的TensorFlow实现 选自 Github 作者:blackecho 机器之心编译 参与:吴攀 这个 repository 是使用 TensorFlow 库实现 ...

  5. 用python画盒图_[519]matplotlib(四)|Python中用matplotlib绘制盒状图(Boxplots)和小提琴图(Violinplots)...

    简单的盒状图 import matplotlib.pyplot as plt import numpy as np all_data = [np.random.normal(0, std, 100) ...

  6. 用python函数画德国国旗代码_求一段python中用class方法绘制国旗的代码!记得不是常见的海龟做法!这个星期给我再加送财富点!...

    展开全部 from matplotlib import patches, pyplot as plt from math import sin, cos, pi fig = plt.figure(fi ...

  7. keras构建卷积神经网络_在python中使用tensorflow s keras api构建卷积神经网络的初学者指南...

    keras构建卷积神经网络 初学者的深度学习 (DEEP LEARNING FOR BEGINNERS) Welcome to Part 2 of the Neural Network series! ...

  8. tensorflow兼容处理 tensorflow.compat.v1 tf.contrib

    20201130 问题提出: v1版本中tensorflow中contrib模块十分丰富,但是发展不可控,因此在v2版本中将这个模块集成到其他模块中去了.在学习tensorflow经常碰到tf.con ...

  9. tensorflow从入门到精通100讲(七)-TensorFlow房价预估使用Keras快速构建模型

    前言 这篇文章承接上一篇tensorflow从入门到精通100讲(二)-IRIS数据集应用实战 https://wenyusuran.blog.csdn.net/article/details/107 ...

最新文章

  1. AliOS Things lorawanapp应用介绍
  2. Android DHCP 启动分析【2】
  3. 二逼平横树——线段树套平衡树
  4. MySQL——数据库的增删改操作
  5. 编写脚本隐藏托盘图标_【Electron-Playground系列】托盘篇
  6. the worries in life: basically two things
  7. 【Matlab】矩阵中选取任意子矩阵
  8. Android studio | Android studio下SVN工具(APP版本管理工具)
  9. python selenium 验证码识别_Python网络爬虫之如何用代码识别图片验证码
  10. 「最简单」的 Core Data 上手指南
  11. Mybatis源码分析第一天------Mybatis实用篇
  12. JACK——BOM Exercise2
  13. use strict
  14. HDU1847 博弈论 水题
  15. last_inner = inner_lateral + inner_top_down RuntimeError: The size of tensor a (81) must match the s
  16. error: component 'clippy' for target 'x86_64-unknown-linux-gnu' is unavailable for download 解决办法
  17. Vapnik-Chervonenkis Dimension 理解
  18. java pacs上传服务_PACS千万家,好看耐用第一家---基于JAVA开发的跨平台PACS系统
  19. 大话信号与系统 --- 奇文共欣赏
  20. v2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\imgwarp.cpp:5594: error: (-215) (M0.t

热门文章

  1. 2020-05-02 自动控制原理常用术语
  2. 事件 绑定,取消冒泡,拖拽 ,点击,事件委托习题
  3. 简单的实现微信获取openid
  4. React-navigation之StackNavigator
  5. Android RecyclerView使用GridLayoutManager间距设置
  6. 二分图常用建图方法及其性质
  7. 支持多编程语言的自动测试系统
  8. Python3实现TCP端口扫描器
  9. Runtime.getRuntime().exec
  10. uploadify多文件上传插件