电脑:Win10家庭版
编辑:Anaconda / Spyder
Tensorflow:tensorflow-gpu
import tensorflow as tf
import keras
from tensorflow.examples.tutorials.mnist import input_data
tf.set_random_seed(1)
mnist = input_data.read_data_sets('MNIST_data/', one_hot=True)
lr = 0.001
training_iters = 100000
batch_size = 128
n_inputs = 28
n_steps = 28
n_hidden_units = 128
n_classes = 10
x = tf.placeholder(tf.float32, [None, n_steps, n_inputs])
y = tf.placeholder(tf.float32, [None, n_classes])
weights = {
'in': tf.Variable(tf.random_normal([n_inputs, n_hidden_units])),
'out': tf.Variable(tf.random_normal([n_hidden_units, n_classes]))
}
biases = {
'in': tf.Variable(tf.constant(0.1, shape=[n_hidden_units, ])),
'out': tf.Variable(tf.constant(0.1, shape=[n_classes, ]))
}
def RNN(X, weights, biases):
# hidden layer for input to cell
X = tf.reshape(X, [-1, n_inputs])
X_in = tf.matmul(X, weights['in']) + biases['in']
X_in = tf.reshape(X_in, [-1, n_steps, n_hidden_units])
# cell
##########################################
cell = tf.contrib.rnn.BasicLSTMCell(n_hidden_units)
init_state = cell.zero_state(batch_size, dtype=tf.float32)
outputs, final_state = tf.nn.dynamic_rnn(cell, X_in,
initial_state=init_state, time_major=False)
outputs = tf.unstack(tf.transpose(outputs, [1,0,2]))
results = tf.matmul(outputs[-1], weights['out']) + biases['out']
pred = RNN(x, weights, biases)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y))
train_op = tf.train.AdamOptimizer(lr).minimize(cost)
correct_pred = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
with tf.Session() as sess:
tf.global_variables_initializer().run()
step = 0
while step * batch_size < training_iters:
batch_xs, batch_ys = mnist.train.next_batch(batch_size)
batch_xs = batch_xs.reshape([batch_size, n_steps, n_inputs])
sess.run([train_op], feed_dict={x: batch_xs,y: batch_ys,})
if step % 20 == 0:
print(sess.run(accuracy, feed_dict={x: batch_xs,y: batch_ys,}))
step += 1
packages\keras\engine\__init__.py", line 8, in <module>
from .training import Model
File "C:\Users\清山\AppData\Local\conda\conda\envs\opencvtest\lib\site-packages\keras\engine\training.py", line 25, in <module>
from .. import callbacks as cbks
File "C:\Users\清山\AppData\Local\conda\conda\envs\opencvtest\lib\site-packages\keras\callbacks.py", line 26, in <module>
from tensorflow.contrib.tensorboard.plugins import projector
File "C:\Users\清山\AppData\Local\conda\conda\envs\opencvtest\lib\site-packages\tensorflow\contrib\__init__.py", line 27, in <module>
from tensorflow.contrib import cudnn_rnn
File "C:\Users\清山\AppData\Local\conda\conda\envs\opencvtest\lib\site-packages\tensorflow\contrib\cudnn_rnn\__init__.py", line 28, in <module>
from tensorflow.contrib.cudnn_rnn.python.ops.cudnn_rnn_ops import CudnnGRU
File "C:\Users\清山\AppData\Local\conda\conda\envs\opencvtest\lib\site-packages\tensorflow\contrib\cudnn_rnn\python\ops\cudnn_rnn_ops.py", line 21, in <module>
from tensorflow.contrib.rnn.python.ops import lstm_ops
File "C:\Users\清山\AppData\Local\conda\conda\envs\opencvtest\lib\site-packages\tensorflow\contrib\rnn\python\ops\lstm_ops.py", line 36, in <module>
resource_loader.get_path_to_datafile("_lstm_ops.so"))
File "C:\Users\清山\AppData\Local\conda\conda\envs\opencvtest\lib\site-packages\tensorflow\contrib\util\loader.py", line 55, in load_op_library
ret = load_library.load_op_library(path)
File "C:\Users\清山\AppData\Local\conda\conda\envs\opencvtest\lib\site-packages\tensorflow\python\framework\load_library.py", line 64, in load_op_library
None, None, error_msg, error_code)
NotFoundError: C:\Users\清山\AppData\Local\conda\conda\envs\opencvtest\lib\site-packages\tensorflow\contrib\rnn\python\ops\_lstm_ops.dll not found
BTW我得到一些信息说我路径中的中文单词会出错,但我运行其他代码,如CNN没有显示这种错误! 而且我也试着把我的中文单词改成关于路径的英文单词,但我的电脑是家庭版,不能让我改变它... Orz.Orz。
答案 0 :(得分:0)
请注意,英语不是我的母语,我可能会犯一些令人困惑的错误。
我遇到了和你一样的问题。 为了直截了当,问题的原因是你想到的汉字。
我是日本人,我使用中文字符作为我的用户名。 因此,我的道路包括像你这样的汉字。
我在Windows上创建了新帐户,其名称不包含中文字符。 然后我重新安装了所有东西。
于是,我的电话(tf.contrib.data.Dataset ......)工作了。
也许某些模块不适用于Unicode,而其他模块则不适用。
如果您要在Windows 10上添加帐户, 你可能会遇到问题,因为有时候Windows 10会对这个操作提出错误 在这种情况下,请在命令提示符下尝试[net User qingshan / add] 您可以创建新帐户。