使用Keras找不到tensorflow 20C

程序代码
#-*- coding: utf-8 -*-
#使用神经网络算法预测销量高低

import pandas as pd

#参数初始化
inputfile = 'D:/python/chapter5/demo/data/sales_data.xls'
data = pd.read_excel(inputfile, index_col = u'序号') #导入数据

#数据是类别标签,要将它转换为数据
#用1来表示“好”、“是”、“高”这三个属性,用0来表示“坏”、“否”、“低”
data[data == u'好'] = 1
data[data == u'是'] = 1
data[data == u'高'] = 1
data[data != 1] = 0
x = data.iloc[:,:3].as_matrix().astype(int)
y = data.iloc[:,3].as_matrix().astype(int)

from keras.models import Sequential
from keras.layers.core import Dense, Activation

model = Sequential() #建立模型
model.add(Dense(input_dim = 3, output_dim = 10))
model.add(Activation('relu')) #用relu函数作为激活函数,能够大幅提供准确度
model.add(Dense(input_dim = 10, output_dim = 1))
model.add(Activation('sigmoid')) #由于是0-1输出,用sigmoid函数作为激活函数

model.compile(loss = 'binary_crossentropy', optimizer = 'adam', class_mode = 'binary')
#编译模型。由于我们做的是二元分类,所以我们指定损失函数为binary_crossentropy,以及模式为binary
#另外常见的损失函数还有mean_squared_error、categorical_crossentropy等,请阅读帮助文件。
#求解方法我们指定用adam,还有sgd、rmsprop等可选

model.fit(x, y, nb_epoch = 1000, batch_size = 10) #训练模型,学习一千次
yp = model.predict_classes(x).reshape(len(y)) #分类预测

from cm_plot import * #导入自行编写的混淆矩阵可视化函数
cm_plot(y,yp).show() #显示混淆矩阵可视化结果

错误提示
Using TensorFlow backend.

Traceback (most recent call last):
File "D:\python\chapter5\demo\code\5-3_neural_network.py", line 19, in
from keras.models import Sequential
File "C:\Python27\lib\site-packages\keras__init__.py", line 3, in
from . import utils
File "C:\Python27\lib\site-packages\keras\utils__init__.py", line 6, in
from . import conv_utils
File "C:\Python27\lib\site-packages\keras\utils\conv_utils.py", line 3, in
from .. import backend as K
File "C:\Python27\lib\site-packages\keras\backend__init__.py", line 83, in
from .tensorflow_backend import *
File "C:\Python27\lib\site-packages\keras\backend\tensorflow_backend.py", line 1, in
import tensorflow as tf
ImportError: No module named tensorflow

2个回答

你要调用TensorFlow,必须要安装它,这样keras才能正常使用

TensorFlow没有安装吧

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Tensorflow代码转到Keras

我现在有Tensortflow的代码和结构图如下,这是AC-GAN中生成器的部分,我用原生tf是可以跑通的,但当我想转到Keras中实现却很头疼。 ``` def batch_norm(inputs, is_training=is_training, decay=0.9): return tf.contrib.layers.batch_norm(inputs, is_training=is_training, decay=decay) # 构建残差块 def g_block(inputs): h0 = tf.nn.relu(batch_norm(conv2d(inputs, 3, 64, 1, use_bias=False))) h0 = batch_norm(conv2d(h0, 3, 64, 1, use_bias=False)) h0 = tf.add(h0, inputs) return h0 # 生成器 # batch_size = 32 # z : shape(32, 128) # label : shape(32, 34) def generator(z, label): with tf.variable_scope('generator', reuse=None): d = 16 z = tf.concat([z, label], axis=1) h0 = tf.layers.dense(z, units=d * d * 64) h0 = tf.reshape(h0, shape=[-1, d, d, 64]) h0 = tf.nn.relu(batch_norm(h0)) shortcut = h0 for i in range(16): h0 = g_block(h0) h0 = tf.nn.relu(batch_norm(h0)) h0 = tf.add(h0, shortcut) for i in range(3): h0 = conv2d(h0, 3, 256, 1, use_bias=False) h0 = tf.depth_to_space(h0, 2) h0 = tf.nn.relu(batch_norm(h0)) h0 = tf.layers.conv2d(h0, kernel_size=9, filters=3, strides=1, padding='same', activation=tf.nn.tanh, name='g', use_bias=True) return h0 ``` ![生成器结构图](https://img-ask.csdn.net/upload/201910/29/1572278934_997142.png) 在Keras中都是先构建Model,在Model中不断的加层 但上面的代码却是中间包含着新旧数据的计算,比如 ``` .... shortcut = h0 .... h0 = tf.add(h0, shortcut) ``` 难不成我还要构建另外一个model作为中间输出吗? 大佬们帮帮忙解释下,或者能不能给出翻译到Keras中应该怎么写

tensorflow环境下只要import keras 就会出现python已停止运行?

python小白在写代码的时候发现只要import keras就会出现python停止运行的情况,目前tensorflow版本1.2.1,keras版本2.1.1,防火墙关了也还是这样,具体代码和问题信息如下,请大神赐教。 ``` # -*- coding: utf-8 -*- import numpy as np from scipy.io import loadmat, savemat from keras.utils import np_utils 问题事件名称: BEX64 应用程序名: pythonw.exe 应用程序版本: 3.6.2150.1013 应用程序时间戳: 5970e8ca 故障模块名称: StackHash_1dc2 故障模块版本: 0.0.0.0 故障模块时间戳: 00000000 异常偏移: 0000000000000000 异常代码: c0000005 异常数据: 0000000000000008 OS 版本: 6.1.7601.2.1.0.256.1 区域设置 ID: 2052 其他信息 1: 1dc2 其他信息 2: 1dc22fb1de37d348f27e54dbb5278e7d 其他信息 3: eae3 其他信息 4: eae36a4b5ffb27c9d33117f4125a75c2 ```

为什么Go中的TensorFlow找不到优化器为python?

<div class="post-text" itemprop="text"> <p>I am a newbie of <code>TensorFlow</code> in <code>Go</code>.</p> <p>There are some doubts during my first traing demo. I just find one optimizer in Go's <code>wrappers.go</code>. </p> <p>But i learn the demos of python,they has serveral optimizers. Like </p> <pre><code>GradientDescentOptimizer AdagradOptimizer AdagradDAOptimizer MomentumOptimizer AdamOptimizer FtrlOptimizer RMSPropOptimizer </code></pre> <p>The similar prefix of func like <code>ResourceApply... GradientDescent Adagrad AdagradDA Momentum Adam Ftrl RMSProp</code>.</p> <p>And they return a option.I don't know what are their purpose. I cant find the relation of them and optimizer.</p> <p>And how can i make a train in <code>Go</code> by <code>TensorFlow</code>.</p> <p>What should I should use like python's <code>tf.Variable</code> in <code>Go</code>?</p> </div>

python3.7中的tensorflow2.0模块没有的问题。

小白刚做手写字识别,遇到tensorflow导入模块的一些问题,模块ModuleNotFoundError: No module named 'tensorflow.examples.tutorials'不会解决。 import keras # 导入Keras import numpy as np from keras.datasets import mnist # 从keras中导入mnist数据集 from keras.models import Sequential # 导入序贯模型 from keras.layers import Dense # 导入全连接层 from keras.optimizers import SGD # 导入优化函数 from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data", one_hot = True) ![图片说明](https://img-ask.csdn.net/upload/201911/17/1573957701_315782.png) 在网上找了好久,也不怎么懂,能告诉我详实点的解决办法。

pip install keras 出现问题

看不懂…求解![图片](https://img-ask.csdn.net/upload/201711/06/1509975346_181543.png)

tensorflow-gpu进行3DUnet训练,jupyter出现服务重启?

我使用了tensorflow1.4.0+CUDA8.0+cudnn6.0进行深度学习的训练,当训练进行到第一个epoch结束的时候就会出现jupyter服务重启的问题,按照之前的博主限制了显卡的占用率,也还是没有效果,查了一下nvidia-smi,显示显卡也有正常调用,很困惑,明明安装了CUDA,版本也应该是正确的,求各位大佬解答。 限制显卡占用的代码 ``` import keras.backend.tensorflow_backend as ktf import tensorflow as tf import os os.environ['CUDA_VISIBLE_DEVICES']='0' Conf = tf.ConfigProto() Conf.gpu_options.per_process_gpu_memory_fraction = 0.5 Conf.gpu_options.allow_growth = True sess = tf.Session(config = Conf) ktf.set_session(sess) ``` 查询nvidia-smi的显示 ![图片说明](https://img-ask.csdn.net/upload/202004/28/1588039244_879973.png) 运行一个epoch后的显示 ![图片说明](https://img-ask.csdn.net/upload/202004/28/1588041915_219677.png) ![图片说明](https://img-ask.csdn.net/upload/202004/28/1588039464_353285.png) 以下是错误信息 ``` Exception in thread Thread-6: Traceback (most recent call last): File "e:\anaconda3\envs\tensorflow\lib\threading.py", line 916, in _bootstrap_inner self.run() File "e:\anaconda3\envs\tensorflow\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "e:\anaconda3\envs\tensorflow\lib\site-packages\keras\utils\data_utils.py", line 568, in data_generator_task generator_output = next(self._generator) File "E:\Jupyter\3DUnetCNN\unet3d\generator.py", line 155, in data_generator skip_blank=skip_blank, permute=permute) File "E:\Jupyter\3DUnetCNN\unet3d\generator.py", line 210, in add_data data, truth = get_data_from_file(data_file, index, patch_shape=patch_shape) File "E:\Jupyter\3DUnetCNN\unet3d\generator.py", line 234, in get_data_from_file data, truth = get_data_from_file(data_file, index, patch_shape=None) File "E:\Jupyter\3DUnetCNN\unet3d\generator.py", line 238, in get_data_from_file x, y = data_file.root.data[index], data_file.root.truth[index, 0] File "e:\anaconda3\envs\tensorflow\lib\site-packages\tables\array.py", line 658, in __getitem__ arr = self._read_slice(startl, stopl, stepl, shape) File "e:\anaconda3\envs\tensorflow\lib\site-packages\tables\array.py", line 762, in _read_slice self._g_read_slice(startl, stopl, stepl, nparr) File "tables\hdf5extension.pyx", line 1585, in tables.hdf5extension.Array._g_read_slice tables.exceptions.HDF5ExtError: HDF5 error back trace File "D:\pytables_hdf5\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5Dio.c", line 199, in H5Dread can't read data File "D:\pytables_hdf5\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5Dio.c", line 601, in H5D__read can't read data File "D:\pytables_hdf5\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5Dchunk.c", line 2282, in H5D__chunk_read chunked read failed File "D:\pytables_hdf5\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5Dselect.c", line 283, in H5D__select_read read error File "D:\pytables_hdf5\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5Dselect.c", line 118, in H5D__select_io can't retrieve I/O vector size File "D:\pytables_hdf5\CMake-hdf5-1.10.5\hdf5-1.10.5\src\H5CX.c", line 1341, in H5CX_get_vec_size can't get default dataset transfer property list End of HDF5 error back trace Problems reading the array data. ```

TensorFlow安装与测试出现问题

win10下配置的TensorFlow学习环境 想测试是否成功 直接上图 ![求解](https://img-ask.csdn.net/upload/201703/20/1490004632_78251.png)

为什么我使用TensorFlow2.0训练的时候loss的变化那么奇怪?

我使用tf2.0搭建了一个deepfm模型用来做一个二分类预测。 训练过程中train loss一直在下降,val loss却一直在上升,并且训练到一半内存就不够用了,这是怎么一回事? ``` Train on 19532 steps, validate on 977 steps Epoch 1/5 19532/19532 [==============================] - 549s 28ms/step - loss: 0.4660 - AUC: 0.8519 - val_loss: 1.0059 - val_AUC: 0.5829 Epoch 2/5 19532/19532 [==============================] - 522s 27ms/step - loss: 0.1861 - AUC: 0.9787 - val_loss: 1.7618 - val_AUC: 0.5590 Epoch 3/5 17150/19532 [=========================>....] - ETA: 1:06 - loss: 0.0877 - AUC: 0.9951 Process finished with exit code 137 ``` 还有个问题,我在设计过程中关闭了eager模式,必须使用了下面代码进行初始化: ``` sess.run([tf.compat.v1.global_variables_initializer(), tf.compat.v1.tables_initializer()]) ``` 但我的代码中使用了其他的初始化方法: ``` initializer = tf.keras.initializers.TruncatedNormal(stddev=stddev, seed=29) regularizer = tf.keras.regularizers.l2(l2_reg) .... dnn_hidden_layer_3 = tf.keras.layers.Dense(64, activation='selu', kernel_initializer=initializer, kernel_regularizer=regularizer)(dnn_hidden_layer_2) .... ``` 我这样做他还是按我定义的初始化方法那样初始化吗? 本人小白,在这里先跪谢大家了!

求问大佬装TensorFlow出现这样的情况是怎么办呀

(TF2.1) C:\Users\lenovo>pip install tensorflow==2.1 Requirement already satisfied: tensorflow==2.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (2.1.0) Requirement already satisfied: termcolor>=1.1.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.1.0) Requirement already satisfied: protobuf>=3.8.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (3.11.3) Requirement already satisfied: absl-py>=0.7.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.9.0) Requirement already satisfied: opt-einsum>=2.3.2 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (3.2.1) Requirement already satisfied: google-pasta>=0.1.6 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.2.0) Requirement already satisfied: wheel>=0.26; python_version >= "3" in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.34.2) Requirement already satisfied: wrapt>=1.11.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.12.1) Requirement already satisfied: gast==0.2.2 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.2.2) Requirement already satisfied: six>=1.12.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.14.0) Requirement already satisfied: numpy<2.0,>=1.16.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.18.4) Requirement already satisfied: tensorboard<2.2.0,>=2.1.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (2.1.1) Requirement already satisfied: tensorflow-estimator<2.2.0,>=2.1.0rc0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (2.1.0) Requirement already satisfied: grpcio>=1.8.6 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.28.1) Requirement already satisfied: astor>=0.6.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.8.1) Requirement already satisfied: scipy==1.4.1; python_version >= "3" in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.4.1) Requirement already satisfied: keras-applications>=1.0.8 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.0.8) Requirement already satisfied: keras-preprocessing>=1.1.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.1.0) Requirement already satisfied: setuptools in f:\anaconda3\envs\tf2.1\lib\site-packages (from protobuf>=3.8.0->tensorflow==2.1) (46.1.3.post20200330) Requirement already satisfied: markdown>=2.6.8 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (3.2.1) Requirement already satisfied: google-auth<2,>=1.6.3 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (1.14.1) Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (0.4.1) Requirement already satisfied: werkzeug>=0.11.15 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (1.0.1) Requirement already satisfied: requests<3,>=2.21.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (2.23.0) Requirement already satisfied: h5py in f:\anaconda3\envs\tf2.1\lib\site-packages (from keras-applications>=1.0.8->tensorflow==2.1) (2.10.0) Requirement already satisfied: pyasn1-modules>=0.2.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (0.2.8) Requirement already satisfied: rsa<4.1,>=3.1.4 in f:\anaconda3\envs\tf2.1\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (4.0) Requirement already satisfied: cachetools<5.0,>=2.0.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (4.1.0) Requirement already satisfied: requests-oauthlib>=0.7.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (1.3.0) Requirement already satisfied: chardet<4,>=3.0.2 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (3.0.4) Requirement already satisfied: idna<3,>=2.5 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (2.9) Requirement already satisfied: certifi>=2017.4.17 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (2020.4.5.1) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (1.25.9) Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in f:\anaconda3\envs\tf2.1\lib\site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (0.4.8) Requirement already satisfied: oauthlib>=3.0.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (3.1.0) (TF2.1) C:\Users\lenovo>python Python 3.7.7 (default, Apr 15 2020, 05:09:04) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf Traceback (most recent call last): File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "F:\anaconda3\envs\TF2.1\lib\imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "F:\anaconda3\envs\TF2.1\lib\imp.py", line 342, in load_dynamic return _load(spec) ImportError: DLL load failed: 找不到指定的模块。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow\__init__.py", line 101, in <module> from tensorflow_core import * File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module> from tensorflow.python.tools import module_util as _module_util File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__ module = self._load() File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow\__init__.py", line 44, in _load module = _importlib.import_module(self.__name__) File "F:\anaconda3\envs\TF2.1\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module> from tensorflow.python import pywrap_tensorflow File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module> raise ImportError(msg) ImportError: Traceback (most recent call last): File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "F:\anaconda3\envs\TF2.1\lib\imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "F:\anaconda3\envs\TF2.1\lib\imp.py", line 342, in load_dynamic return _load(spec) ImportError: DLL load failed: 找不到指定的模块。 Failed to load the native TensorFlow runtime. See https://www.tensorflow.org/install/errors for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.

尝试打开tensorboard的时候ImportError: DLL load failed: 找不到指定的模块。

(tensorflow) C:\Users\14228\PycharmProjects\untitled>tensorboard --logdir=logs Traceback (most recent call last): File "d:\anaconda3\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "d:\anaconda3\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "D:\Anaconda3\Scripts\tensorboard.exe\__main__.py", line 5, in <module> File "d:\anaconda3\lib\site-packages\tensorboard\main.py", line 40, in <module> from tensorboard import default File "d:\anaconda3\lib\site-packages\tensorboard\default.py", line 38, in <module> from tensorboard.plugins.audio import audio_plugin File "d:\anaconda3\lib\site-packages\tensorboard\plugins\audio\audio_plugin.py", line 30, in <module> from tensorboard.util import tensor_util File "d:\anaconda3\lib\site-packages\tensorboard\util\tensor_util.py", line 20, in <module> import numpy as np File "d:\anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module> from . import _distributor_init File "d:\anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module> from . import _mklinit ImportError: DLL load failed: 找不到指定的模块。

keras 并发load_model报错

我通过web代码实时加载模型进行预测,但报如下错误 Traceback (most recent call last): File "/root/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__ return self.wsgi_app(environ, start_response) File "/root/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app response = self.handle_exception(e) File "/root/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception reraise(exc_type, exc_value, tb) File "/root/anaconda3/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/root/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app response = self.full_dispatch_request() File "/root/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request rv = self.handle_user_exception(e) File "/root/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception reraise(exc_type, exc_value, tb) File "/root/anaconda3/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise raise value File "/root/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request rv = self.dispatch_request() File "/root/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/root/anaconda3/code/App.py", line 41, in predict model=load_model(root_path+model_name) File "/root/anaconda3/lib/python3.6/site-packages/keras/models.py", line 249, in load_model topology.load_weights_from_hdf5_group(f['model_weights'], model.layers) File "/root/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 3008, in load_weights_from_hdf5_group K.batch_set_value(weight_value_tuples) File "/root/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2189, in batch_set_value get_session().run(assign_ops, feed_dict=feed_dict) File "/root/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 895, in run run_metadata_ptr) File "/root/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1071, in _run + e.args[0]) TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(1, 16), dtype=float32) is not an element of this graph.

TensorFlow2.0训练模型时,指标不收敛一直上升到1

我尝试着使用tf2.0来搭建一个DeepFM模型来预测用户是否喜欢某部影片, optimizer选择Adam,loss选择BinaryCrossentropy,评价指标是AUC; 因为涉及到了影片ID,所以我用了shared_embedding,并且必须关闭eager模式; 选用binary_crossentropy作为损失函数时模型在训练时AUC很快就到1了,但选用categorical_crossentropy时loss没太大变化,并且AUC一直保持在0.5,准确率也一直在0.5附近震荡。 下面是选用binary_crossentropy时的输出日志: ![图片说明](https://img-ask.csdn.net/upload/202002/21/1582271521_157835.png) ![图片说明](https://img-ask.csdn.net/upload/202002/21/1582271561_279055.png) 下面是我的代码: ``` one_order_feature_layer = tf.keras.layers.DenseFeatures(one_order_feature_columns) one_order_feature_layer_outputs = one_order_feature_layer(feature_layer_inputs) two_order_feature_layer = tf.keras.layers.DenseFeatures(two_order_feature_columns) two_order_feature_layer_outputs = two_order_feature_layer(feature_layer_inputs) # lr部分 lr_layer = tf.keras.layers.Dense(len(one_order_feature_columns), kernel_initializer=initializer)( one_order_feature_layer_outputs) # fm部分 reshape = tf.reshape(two_order_feature_layer_outputs, [-1, len(two_order_feature_columns), two_order_feature_columns[0].dimension]) sum_square = tf.square(tf.reduce_sum(reshape, axis=1)) square_sum = tf.reduce_sum(tf.square(reshape), axis=1) fm_layers = tf.multiply(0.5, tf.subtract(sum_square, square_sum)) # DNN部分 dnn_hidden_layer_1 = tf.keras.layers.Dense(64, activation='selu', kernel_initializer=initializer, kernel_regularizer=regularizer)(two_order_feature_layer_outputs) dnn_hidden_layer_2 = tf.keras.layers.Dense(64, activation='selu', kernel_initializer=initializer, kernel_regularizer=regularizer)(dnn_hidden_layer_1) dnn_hidden_layer_3 = tf.keras.layers.Dense(64, activation='selu', kernel_initializer=initializer, kernel_regularizer=regularizer)(dnn_hidden_layer_2) dnn_dropout = tf.keras.layers.Dropout(0.5, seed=29)(dnn_hidden_layer_3) # 连接并输出 concatenate_layer = tf.keras.layers.concatenate([lr_layer, fm_layers, dnn_dropout]) out_layer = tf.keras.layers.Dense(1, activation='sigmoid')(concatenate_layer) model = tf.keras.Model(inputs=[v for v in feature_layer_inputs.values()], outputs=out_layer) model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=learning_rate), loss=tf.keras.losses.BinaryCrossentropy(), metrics=['AUC']) # tf.keras.utils.plot_model(model, 'test.png', show_shapes=True) train_ds = make_dataset(train_df, buffer_size=None, shuffle=True) test_ds = make_dataset(test_df) with tf.compat.v1.Session() as sess: sess.run([tf.compat.v1.global_variables_initializer(), tf.compat.v1.tables_initializer()]) model.fit(train_ds, epochs=5) loss, auc = model.evaluate(test_ds) print("AUC", auc) ```

请问tensorflow中程序运行完如何释放显存

在网上没检索到相关的代码。 已经掌握按比例/按需显存管理,现在想让模型在运行结束后自动释放显存,qing'wen'you'shen'me'ban'fa

保存keras模型时出现的问题

求助各路大神,小弟最近用keras跑神经网络模型,在训练和测试时都很好没问题,但是在保存时出现问题 小弟保存模型用的语句: json_string = model.to_json() open('my_model_architecture.json', 'w').write(json_string) #保存网络结构 model.save_weights('my_model_weights.h5',overwrite='true') #保存权重 但是运行后会显示Process finished with exit code -1073741819 (0xC0000005) 然后保存权重的.h5文件没有内容 求助各位大神是怎么回事啊

基于keras写的模型中自定义的函数(如损失函数)如何保存到模型中?

```python batch_size = 128 original_dim = 100 #25*4 latent_dim = 16 # z的维度 intermediate_dim = 256 # 中间层的维度 nb_epoch = 50 # 训练轮数 epsilon_std = 1.0 # 重参数 #my tips:encoding x = Input(batch_shape=(batch_size,original_dim)) h = Dense(intermediate_dim, activation='relu')(x) z_mean = Dense(latent_dim)(h) # mu z_log_var = Dense(latent_dim)(h) # sigma #my tips:Gauss sampling,sample Z def sampling(args): # 重采样 z_mean, z_log_var = args epsilon = K.random_normal(shape=(128, 16), mean=0., stddev=1.0) return z_mean + K.exp(z_log_var / 2) * epsilon # note that "output_shape" isn't necessary with the TensorFlow backend # my tips:get sample z(encoded) z = Lambda(sampling, output_shape=(latent_dim,))([z_mean, z_log_var]) # we instantiate these layers separately so as to reuse them later decoder_h = Dense(intermediate_dim, activation='relu') # 中间层 decoder_mean = Dense(original_dim, activation='sigmoid') # 输出层 h_decoded = decoder_h(z) x_decoded_mean = decoder_mean(h_decoded) #my tips:loss(restruct X)+KL def vae_loss(x, x_decoded_mean): xent_loss = original_dim * objectives.binary_crossentropy(x, x_decoded_mean) kl_loss = - 0.5 * K.mean(1 + z_log_var - K.square(z_mean) - K.exp(z_log_var), axis=-1) return xent_loss + kl_loss vae = Model(x, x_decoded_mean) vae.compile(optimizer='rmsprop', loss=vae_loss) vae.fit(x_train, x_train, shuffle=True, epochs=nb_epoch, verbose=2, batch_size=batch_size, validation_data=(x_valid, x_valid)) vae.save(path+'//VAE.h5') ``` 一段搭建VAE结构的代码,在保存模型后调用时先是出现了sampling中一些全局变量未定义的问题,将变量改为确定数字后又出现了vae_loss函数未定义的问题(unknown loss function: vae_loss) 个人认为是模型中自定义的函数在保存上出现问题,但是也不知道怎么解决。刚刚上手keras和tensorflow这些框架,很多问题是第一次遇到,麻烦大神们帮帮忙!感谢!

装TensorFlow出现了这些问题是什么情况呀

(TF2.1) C:\Users\lenovo>pip install tensorflow==2.1 Requirement already satisfied: tensorflow==2.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (2.1.0) Requirement already satisfied: termcolor>=1.1.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.1.0) Requirement already satisfied: protobuf>=3.8.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (3.11.3) Requirement already satisfied: absl-py>=0.7.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.9.0) Requirement already satisfied: opt-einsum>=2.3.2 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (3.2.1) Requirement already satisfied: google-pasta>=0.1.6 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.2.0) Requirement already satisfied: wheel>=0.26; python_version >= "3" in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.34.2) Requirement already satisfied: wrapt>=1.11.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.12.1) Requirement already satisfied: gast==0.2.2 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.2.2) Requirement already satisfied: six>=1.12.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.14.0) Requirement already satisfied: numpy<2.0,>=1.16.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.18.4) Requirement already satisfied: tensorboard<2.2.0,>=2.1.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (2.1.1) Requirement already satisfied: tensorflow-estimator<2.2.0,>=2.1.0rc0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (2.1.0) Requirement already satisfied: grpcio>=1.8.6 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.28.1) Requirement already satisfied: astor>=0.6.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (0.8.1) Requirement already satisfied: scipy==1.4.1; python_version >= "3" in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.4.1) Requirement already satisfied: keras-applications>=1.0.8 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.0.8) Requirement already satisfied: keras-preprocessing>=1.1.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorflow==2.1) (1.1.0) Requirement already satisfied: setuptools in f:\anaconda3\envs\tf2.1\lib\site-packages (from protobuf>=3.8.0->tensorflow==2.1) (46.1.3.post20200330) Requirement already satisfied: markdown>=2.6.8 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (3.2.1) Requirement already satisfied: google-auth<2,>=1.6.3 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (1.14.1) Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (0.4.1) Requirement already satisfied: werkzeug>=0.11.15 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (1.0.1) Requirement already satisfied: requests<3,>=2.21.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (2.23.0) Requirement already satisfied: h5py in f:\anaconda3\envs\tf2.1\lib\site-packages (from keras-applications>=1.0.8->tensorflow==2.1) (2.10.0) Requirement already satisfied: pyasn1-modules>=0.2.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (0.2.8) Requirement already satisfied: rsa<4.1,>=3.1.4 in f:\anaconda3\envs\tf2.1\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (4.0) Requirement already satisfied: cachetools<5.0,>=2.0.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (4.1.0) Requirement already satisfied: requests-oauthlib>=0.7.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (1.3.0) Requirement already satisfied: chardet<4,>=3.0.2 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (3.0.4) Requirement already satisfied: idna<3,>=2.5 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (2.9) Requirement already satisfied: certifi>=2017.4.17 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (2020.4.5.1) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests<3,>=2.21.0->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (1.25.9) Requirement already satisfied: pyasn1<0.5.0,>=0.4.6 in f:\anaconda3\envs\tf2.1\lib\site-packages (from pyasn1-modules>=0.2.1->google-auth<2,>=1.6.3->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (0.4.8) Requirement already satisfied: oauthlib>=3.0.0 in f:\anaconda3\envs\tf2.1\lib\site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.2.0,>=2.1.0->tensorflow==2.1) (3.1.0) (TF2.1) C:\Users\lenovo>python Python 3.7.7 (default, Apr 15 2020, 05:09:04) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf Traceback (most recent call last): File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "F:\anaconda3\envs\TF2.1\lib\imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "F:\anaconda3\envs\TF2.1\lib\imp.py", line 342, in load_dynamic return _load(spec) ImportError: DLL load failed: 找不到指定的模块。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow\__init__.py", line 101, in <module> from tensorflow_core import * File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\__init__.py", line 40, in <module> from tensorflow.python.tools import module_util as _module_util File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow\__init__.py", line 50, in __getattr__ module = self._load() File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow\__init__.py", line 44, in _load module = _importlib.import_module(self.__name__) File "F:\anaconda3\envs\TF2.1\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\__init__.py", line 49, in <module> from tensorflow.python import pywrap_tensorflow File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 74, in <module> raise ImportError(msg) ImportError: Traceback (most recent call last): File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow.py", line 58, in <module> from tensorflow.python.pywrap_tensorflow_internal import * File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 28, in <module> _pywrap_tensorflow_internal = swig_import_helper() File "F:\anaconda3\envs\TF2.1\lib\site-packages\tensorflow_core\python\pywrap_tensorflow_internal.py", line 24, in swig_import_helper _mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname, description) File "F:\anaconda3\envs\TF2.1\lib\imp.py", line 242, in load_module return load_dynamic(name, filename, file) File "F:\anaconda3\envs\TF2.1\lib\imp.py", line 342, in load_dynamic return _load(spec) ImportError: DLL load failed: 找不到指定的模块。 Failed to load the native TensorFlow runtime. See https://www.tensorflow.org/install/errors for some common reasons and solutions. Include the entire stack trace above this error message when asking for help.

pycharm没有numpy模块

本人深度学习萌新,准备用yolov3进行车的识别,看了一个大佬的文章开始操作但是在调用numpy时报错,按照站内一些大佬指引配置了python的anaconda的环境仍然不行,而且另外开的文件用numpy就可以正常运作不报错、 ``` C:\Users\27568\Anaconda3\envs\untitled\python.exe D:/keras-yolo3-master/train.py Traceback (most recent call last): File "D:/keras-yolo3-master/train.py", line 7, in <module> import numpy as np ModuleNotFoundError: No module named 'numpy' Process finished with exit code 1 ``` 附上原代码和随意写的新代码 ``` """ Retrain the YOLO model for your own dataset. """ import numpy as np import keras.backend as K from keras.layers import Input, Lambda from keras.models import Model from keras.callbacks import TensorBoard, ModelCheckpoint, EarlyStopping ``` 新代码: ``` import numpy as np print("hello") ``` 并不报错

tensorflow CNN训练图片分类的时候,模型训练不出来,准确率0.1(分了十类),模型失效,是什么原因?

``` def compute_accuracy(v_xs, v_ys): global prediction y_pre = sess.run(prediction, feed_dict={xs: v_xs, keep_prob: 1}) correct_prediction = tf.equal(tf.argmax(y_pre,1), tf.argmax(v_ys,1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) result = sess.run(accuracy, feed_dict={xs: v_xs, ys: v_ys, keep_prob: 1}) return result def weight_variable(shape): initial = tf.truncated_normal(shape, stddev=0.1) return tf.Variable(initial) def bias_variable(shape): initial = tf.constant(0.1, shape=shape) return tf.Variable(initial) def conv2d(x, W): # stride [1, x_movement, y_movement, 1] # Must have strides[0] = strides[3] = 1 return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME') def max_pool_2x2(x): # stride [1, x_movement, y_movement, 1] return tf.nn.max_pool(x, ksize=[1,4,4,1], strides=[1,4,4,1], padding='SAME') # define placeholder for inputs to network xs = tf.placeholder(tf.float32, [None, 65536])/255. # 256x256 ys = tf.placeholder(tf.float32, [None, 10]) keep_prob = tf.placeholder(tf.float32) x_image = tf.reshape(xs, [-1, 256, 256, 1]) # print(x_image.shape) # [n_samples, 28,28,1] ## conv1 layer ## W_conv1 = weight_variable([3,3, 1,64]) # patch 5x5, in size 1, out size 32 b_conv1 = bias_variable([64]) h_conv1 = tf.nn.elu(conv2d(x_image, W_conv1) + b_conv1) # output size 28x28x32 h_pool1 = tf.nn.max_pool(h_conv1, ksize=[1,2,2,1], strides=[1,2,2,1], padding='SAME') # output size 14x14x32 ## conv2 layer ## W_conv2 = weight_variable([3,3, 64, 128]) # patch 5x5, in size 32, out size 64 b_conv2 = bias_variable([128]) h_conv2 = tf.nn.elu(conv2d(h_pool1, W_conv2) + b_conv2) # output size 14x14x64 h_pool2 = max_pool_2x2(h_conv2) # output size 7x7x64 ## conv3 layer ## W_conv3 = weight_variable([3,3, 128, 256]) # patch 5x5, in size 32, out size 64 b_conv3 = bias_variable([256]) h_conv3 = tf.nn.elu(conv2d(h_pool2, W_conv3) + b_conv3) # output size 14x14x64 h_pool3 = max_pool_2x2(h_conv3) ## conv4 layer ## W_conv4 = weight_variable([3,3, 256, 512]) # patch 5x5, in size 32, out size 64 b_conv4 = bias_variable([512]) h_conv4 = tf.nn.elu(conv2d(h_pool3, W_conv4) + b_conv4) # output size 14x14x64 h_pool4 = max_pool_2x2(h_conv4) # ## conv5 layer ## # W_conv5 = weight_variable([3,3, 512, 512]) # patch 5x5, in size 32, out size 64 # b_conv5 = bias_variable([512]) # h_conv5 = tf.nn.relu(conv2d(h_pool3, W_conv4) + b_conv4) # output size 14x14x64 # h_pool5 = max_pool_2x2(h_conv4) ## fc1 layer ## W_fc1 = weight_variable([2*2*512, 128]) b_fc1 = bias_variable([128]) # [n_samples, 7, 7, 64] ->> [n_samples, 7*7*64] h_pool4_flat = tf.reshape(h_pool4, [-1, 2*2*512]) h_fc1 = tf.nn.elu(tf.matmul(h_pool4_flat, W_fc1) + b_fc1) h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob) ## fc2 layer ## W_fc2 = weight_variable([128, 10]) b_fc2 = bias_variable([10]) prediction = tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) # 定义优化器和训练op loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=ys, logits=prediction)) train_step = tf.train.RMSPropOptimizer((1e-3)).minimize(loss) correct_prediction = tf.equal(tf.argmax(prediction, 1), tf.argmax(ys, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) # 用于保存和载入模型 saver = tf.train.Saver() def int2onehot(train_batch_ys): num_labels = train_batch_ys.shape[0] num_classes=10 index_offset = np.arange(num_labels) * num_classes labels_one_hot = np.zeros((num_labels, num_classes),dtype=np.float32) labels_one_hot.flat[index_offset + train_batch_ys.ravel()] = 1 return labels_one_hot train_label_lists, train_data_lists, train_fname_lists = read_tfrecords(train_tfrecord_file) iterations = 100 with tf.Session() as sess: sess.run(tf.global_variables_initializer()) # 执行训练迭代 for it in range(iterations): # 这里的关键是要把输入数组转为np.array for i in range(200): train_label_list = train_label_lists[i] train_data_list= train_data_lists[i] train_name_list = train_fname_lists[i] #print("shape of train_data_list: {}\tshape of train_label_list: {}".format(train_data_list.shape, train_label_list.shape)) #print('该批文件名:',train_name_list) print('该批标签:',train_label_list) # 计算有多少类图片 #num_classes = len(set(train_label_list)) #print("num_classes:",num_classes) train_batch_xs = train_data_list train_batch_xs = np.reshape(train_batch_xs, (-1, 65536)) train_batch_ys = train_label_list train_batch_ys = int2onehot(train_batch_ys) #print('第'+str(i)+'批-----------') print("连接层1之后----------------------------------------") for i in range(80): print("元素"+str(i)+":",sess.run(tf.reduce_mean(sess.run(h_fc1_drop,feed_dict={xs: train_batch_xs, ys: train_batch_ys, keep_prob: 0.5})[i].shape))) print("元素"+str(i)+":",sess.run(h_fc1_drop,feed_dict={xs: train_batch_xs, ys: train_batch_ys, keep_prob: 0.5})[i]) print("连接层2之后----------------------------------------") for i in range(80): print("元素"+str(i)+":",sess.run(tf.reduce_mean(sess.run(prediction,feed_dict={xs: train_batch_xs, ys: train_batch_ys, keep_prob: 0.5})[i].shape))) print("元素"+str(i)+":",sess.run(prediction,feed_dict={xs: train_batch_xs, ys: train_batch_ys, keep_prob: 0.5})[i]) #loss.run(feed_dict={xs: train_batch_xs, ys: train_batch_ys, keep_prob: 0.5}) train_step.run(feed_dict={xs: train_batch_xs, ys: train_batch_ys, keep_prob: 0.5}) time.sleep(7) # 每完成五次迭代,判断准确度是否已达到100%,达到则退出迭代循环 iterate_accuracy = 0 if it%5 == 0: iterate_accuracy = accuracy.eval(feed_dict={xs: train_batch_xs, ys: train_batch_ys, keep_prob: 0.5}) print ('iteration %d: accuracy %s' % (it, iterate_accuracy)) if iterate_accuracy >= 1: break; print ('完成训练!') ```

用tensorflow-gpu跑SSD-Mobilenet模型GPU使用率很低这是为什么

![这是GPU运行情况](https://img-ask.csdn.net/upload/201903/16/1552742279_678606.png) 这是GPU运行情况 ![这是训练过程](https://img-ask.csdn.net/upload/201903/16/1552742314_282445.png) 这是训练过程

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

ArrayList源码分析(入门篇)

ArrayList源码分析 前言: 写这篇博客的主要原因是,在我上一次参加千牵科技Java实习生面试时,有被面试官问到ArrayList为什么查找的速度较快,插入和删除的速度较慢?当时我回答得不好,很大的一部分原因是因为我没有阅读过ArrayList源码,虽然最后收到Offer了,但我拒绝了,打算寒假学得再深入些再广泛些,下学期开学后再去投递其他更好的公司。为了更加深入理解ArrayList,也为

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

玩转springboot启动banner定义所得

最近接手了一个springboot项目,不是不熟悉这个框架,启动时打印的信息吸引了我。 这不是我熟悉的常用springboot的打印信息啊,我打开自己的项目: 还真是的,不用默认的感觉也挺高大上的。一时兴起,就去研究了一下源代码,还正是有些收获,稍后我会总结一下。正常情况下做为一个老程序员,是不会对这种小儿科感兴趣的,不就是一个控制台打印嘛。哈哈! 于是出于最初的好奇,研究了项目的源代码。看到

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

你打算用Java 8一辈子都不打算升级到Java 14,真香

我们程序员应该抱着尝鲜、猎奇的心态,否则就容易固步自封,技术停滞不前。

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

立即提问
相关内容推荐