![](img/tl_transparent_logo.png)
TensorLayer是一个崭新的基于TensorFlow的深度学习与增强学习开发库。它提供大量的神经网络相关组件和函数来帮助顶尖研究人员和一线工程师解决复杂的人工智能问题。 本仓库维护了TensorLayer的中文文档。相对于英文文档,中文文档会有一定滞后性。
TensorLayer拥有大量的华人使用者和开发者。官方的中文社群包括了QQ群和微信群进行广泛的讨论。官方英文渠道是Slack。申请加入这些社群时,请star官方项目,并告知github用户名。
TensorLayer 中文文档
Home Page: http://tensorlayercn.readthedocs.io
tutoiral*.py utils.py cost.py 等更新了
Conv2d(n, 64, (5, 5), (1, 1), padding='SAME', name='cnn2')
这个函数Conv2d的W_init_args = {}, b_init_args = {}参数没有根据输入加入dtype,而参数初始化本身是做float32的,导致了无法运行。
需加入W_init_args={"dtype":tf.float16},b_init_args={"dtype":tf.float16}参数
with tl.distributed.DistributedSession(task_spec=task_spec) as sess:
tl.files.load_and_assign_npz(sess=sess, name='n.npz', network=net)
这样写会报错:
RuntimeError: Graph is finalized and cannot be modified.
帅哥,我电脑wechat掉线了,在公海上手机没法scan QR code了。。突然发现没有你的邮箱,有事Line或邮件联系。。
tl.prepro.obj_box_crop
when I set “is_center=False, is_random=True ”
the changed label is not in the correct position
I just found.... did I use this function wrong?
I cannot post pic...
是否需要自定义输入层来实现?
参考例子:Keras/多输入和多输出模型
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:205: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
return f(*args, **kwds)
是3.6版本的python不兼容吗
When I look at the source code of tl.layers.seq2seq, something confused me. In traditional seq2seq model, the encode part should return the last output instead of all output. But in the "network_encode" part, “return_last” has been set to "False", that means encode part will return all outputs. Why? Isn't it better to set "return_last=True"? Thanks!
(英文水平不怎么好,所以还是对问题加一段中文翻译好了:经典seq2seq模型的encode部分应该是前面隐藏单元的加权,并输出最后一个unit。但tl.layers.seq2seq源代码中network_encode部分,用DynamicRNNLayer函数进行编码,return_last函数被设置为False,是否意味着encode部分会输出所有单元呢?为什么不是设为True只输出最后一个呢?)
num of params: 1276810
layer 0: Tensor("drop1/mul:0", shape=(?, 784), dtype=float32)
layer 1: Tensor("relu1/Relu:0", shape=(?, 800), dtype=float32)
layer 2: Tensor("drop2/mul:0", shape=(?, 800), dtype=float32)
layer 3: Tensor("relu2/Relu:0", shape=(?, 800), dtype=float32)
layer 4: Tensor("drop3/mul:0", shape=(?, 800), dtype=float32)
layer 5: Tensor("output_layer/Identity:0", shape=(?, 10), dtype=float32)
learning_rate: 0.000100
batch_size: 128
Epoch 1 of 1 took 1.700945s
train loss: 0.439682
val loss: 0.384359
val acc: 0.880900
Traceback (most recent call last):
File "tutorial_mnist.py", line 562, in
main_test_layers(model='relu') # model = relu, dropconnect
File "tutorial_mnist.py", line 154, in main_test_layers
to save the feature images for different dataset")
Exception: You should change visualize_W(), if you want to save the feature images for different dataset
当我用文档提供的例子tutorial_mnist_distributed做实验的时候,我发现当我把创建Session的代码改为:
with tl.distributed.DistributedSession(task_spec=task_spec,checkpoint_dir="checkpoint",save_checkpoint_secs=1000,save_summaries_steps=100,save_summaries_secs=None) as sess:
这时候会出现RuntimeError:"Global step should be created to use StepCounterHook."
另外单独指定task_spec和checkpoint_dir属性也会报错,
tl.distributed.DistributedSession(task_spec=task_spec,checkpoint_dir="checkpoint") as sess:
TypeError: unorderable types: object() > int()
这个错误可以通过指定save_summaries_steps和save_summaries_secs解决。
感觉tensorlayer对分布式的支持并不成熟,有很多问题。
重点在加粗的部分,有没有更加合适的翻译?
以TF为参考:
tf.Variable
tf.nn.bias_add
tf.matmul
tf.nn.relu
tf.nn.dropout
tf.reduce_mean
tf.nn.sparse_softmax_cross_entropy_with_logits
tf.optimizers.Adam
TF求导例子:
optimizer = tf.optimizers.Adam(learning_rate=0.0001)
with tf.GradientTape() as tape:
## compute outputs
_logits = MLP(X_batch, foo=1)
## compute loss and update model
_loss = tl.cost.cross_entropy(_logits, y_batch, name='train_loss')
grad = tape.gradient(_loss, MLP.weights)
optimizer.apply_gradients(zip(grad, MLP.weights))
我在 windows下通过 xshell 访问 centos,在 centos 中运行 example 中的 tutorial_mnist.py 就报异常了:QXcbConnection: Could not connect to display
原因应该是服务器中不能运行 GUI 程序
错误的位置应该是 tutorial_mnist.py 中第 390 行左右用到的 tl.visualize ,再进去就是 tl.visualize 这个文件中的 import matplotlib.pyplot as plt
我的解决方法:在 tl.visualize 源码中把被注释掉的 matplotlib.use('Agg')
去掉注释,就可以了。
现在我想请问一下有没有其他途径可以解决这个问题呢?
def train(x_data, y_data):
x_train, y_train, x_valid, y_valid = split_data(x_data, y_data)
# train
#
sess = tf.InteractiveSession()
x = tf.placeholder(tf.float32, (None, 227, 227, 3))
y_ = tf.placeholder(tf.int64, (None, 17))
net = model_alexnet(x, 17)
y = net.outputs
# define cost and metric
cost = tl.cost.cross_entropy(y, tf.argmax(y_, 1), name='cost')
correct_predic = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
acc = tf.reduce_mean(tf.cast(correct_predic, tf.float32))
# y_op = tf.argmax(tf.nn.softmax(y))
train_op = tf.train.AdamOptimizer(1e-5).minimize(cost)
tl.layers.initialize_global_variables(sess)
# 导入参数 --> 用同一段代码训练过得参数继续训练,提示load success但是fit的时候正确率还是从很
# 低开始,像是从头开始训练了
#
if os.path.isfile('net_params.npz'):
print('load pre-train params...')
tl.files.load_and_assign_npz(sess, 'net_params.npz', net)
tl.utils.fit(sess, net, train_op, cost, x_train, y_train, x, y_,
acc, batch_size=32, n_epoch=100, print_freq=10,
X_val=x_valid, y_val=y_valid, eval_train=True, tensorboard=True)
tl.files.save_npz(net.all_params, name='net_params.npz', sess=sess)
sess.close()
如上注释...
加了 DeConvxxLayer, SlimNetsLayer etc.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.