Giter Site home page Giter Site logo

hzy46 / deep-learning-21-examples Goto Github PK

View Code? Open in Web Editor NEW
4.4K 162.0 1.8K 138.54 MB

《21个项目玩转深度学习———基于TensorFlow的实践详解》配套代码

Python 91.35% HCL 0.15% HTML 1.59% Jupyter Notebook 2.33% Makefile 0.03% Shell 1.11% MATLAB 0.67% CSS 0.44% JavaScript 2.10% Dockerfile 0.23%

deep-learning-21-examples's Introduction

Deep-Learning-21-Examples

本工程是《21个项目玩转深度学习———基于TensorFlow的实践详解》的配套代码,代码推荐的运行环境为:Ubuntu 14.04,Python 2.7、TensorFlow >= 1.4.0。请尽量使用类UNIX系统和Python 2运行本书的代码。

欢迎有兴趣的同学猛戳下面的链接购买:

写作这本书的初衷是希望提供一个深度学习实践案例的合集,让每个人都可以在“动手实验”的过程中,比较轻松地掌握深度学习和TensorFlow的使用技巧,并且能完整地做出一些有意思的项目。希望大家能在实践的过程中找到乐趣,如果有任何问题,欢迎通过issues提出纠错或改进建议。

快速指引

以下是各章代码详细的运行方法:

  1. MNIST机器学习入门
  2. CIFAR-10与ImageNet图像识别
  3. 打造自己的图像识别模型
  4. Deep Dream
  5. 深度学习中的目标检测
  6. 人脸检测和人脸识别
  7. 图像风格迁移
  8. GAN与DCGAN入门
  9. pix2pix模型与自动上色技术
  10. 超分辨率:让图像变得更清晰
  11. CycleGAN与非配对图像转换
  12. RNN基本结构与Char RNN文本生成
  13. 序列分类问题详解
  14. 词的向量表示:word2vec与词嵌入
  15. 在TensorFlow中进行时间序列预测
  16. 神经网络机器翻译技术
  17. 看图说话:将图像转换为文字
  18. 强化学习入门之Q Learning
  19. 强化学习入门之SARSA算法
  20. 深度强化学习:Deep Q Learning
  21. 策略梯度(Policy Gradient)算法

本书包含的项目主要有三部分:第1~11章主要介绍CNN相关的项目,其中8~11章为GAN模型和它的几个重要变体;第12~17章主要介绍RNN、LSTM 相关的项目;第18~21章主要介绍强化学习相关的项目。

各章data文件夹下载地址

本工程主要包含的是项目的源代码文件,以chapter_1/ ~ chapter_21/ 标识。在有的章节中,还会额外需要一些数据集、模型等文件,我们用chapter_<章节名>_data/来表示。

例如:第四章有chapter_4/和chapter_4_data/两个文件夹,前者是源代码,后者是在运行程序时会用的数据文件。

由于数据文件通常比较大,建议读者在用到时候再进行下载,下载地址为:https://pan.baidu.com/s/1i7pKvFf,提取码:1kmf。

其他链接

  • 意见反馈邮箱:hzydl21 [at] 163.com
  • 我的专栏博客:AI Insight

致谢

感谢电子工业出版社的孙学瑛女士和宋亚东先生为本书付出的努力,同时也感谢刘婧源同学给本书的宝贵建议。本书对于来自于网络的代码,在书中和配套代码的Readme文件中,均作了引用说明,在此也对原作者表示深深的感谢。

deep-learning-21-examples's People

Contributors

hzy46 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

deep-learning-21-examples's Issues

第3章 3.3.4的训练一定要GPU参与吗?

chapter_3/slim# python train_image_classifier.py --train_dir=satellite/train_dir --dataset_name=satellite --dataset_split_name=train --dataset_dir=satellite/data --model_name=inception_v3 --checkpoint_path=satellite/pretrained/inception_v3.ckpt --checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits --trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits --max_number_of_steps=100000 --batch_size=32 --learning_rate=0.001 --learning_rate_decay_type=fixed --save_interval_secs=300 --save_summaries_secs=2 --log_every_n_steps=10 --optimizer=rmsprop --weight_decay=0.00004
WARNING:tensorflow:From train_image_classifier.py:398: create_global_step (from tensorflow.contrib.framework.python.ops.variables) is deprecated and will be removed in a future version.
Instructions for updating:
Please switch to tf.train.create_global_step
INFO:tensorflow:Summary name /clone_loss is illegal; using clone_loss instead.
INFO:tensorflow:Fine-tuning from satellite/pretrained/inception_v3.ckpt
2018-05-31 22:46:18.586097: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 AVX512F FMA
INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.InvalidArgumentError'>, Cannot assign a device for operation 'InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
[[Node: InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1 = VariableV2_class=["loc:@InceptionV3/AuxLogits/Conv2d_2b_1x1/biases"], container="", dtype=DT_FLOAT, shape=[6], shared_name="", _device="/device:GPU:0"]]

Caused by op u'InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1', defined at:
File "train_image_classifier.py", line 573, in
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train_image_classifier.py", line 540, in main
global_step=global_step)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/optimizer.py", line 474, in apply_gradients
self._create_slots([_get_variable_for(v) for v in var_list])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/rmsprop.py", line 111, in _create_slots
self._zeros_slot(v, "momentum", self._name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/optimizer.py", line 796, in _zeros_slot
named_slots[_var_key(var)] = slot_creator.create_zeros_slot(var, op_name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/slot_creator.py", line 174, in create_zeros_slot
colocate_with_primary=colocate_with_primary)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/slot_creator.py", line 148, in create_slot_with_initializer
dtype)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/slot_creator.py", line 67, in _create_slot_var
validate_shape=validate_shape)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 1203, in get_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 1092, in get_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 425, in get_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 394, in _true_getter
use_resource=use_resource, constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 805, in _get_single_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 213, in init
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 309, in _init_from_args
name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/state_ops.py", line 133, in variable_op_v2
shared_name=shared_name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 927, in _variable_v2
shared_name=shared_name, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1470, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
[[Node: InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1 = VariableV2_class=["loc:@InceptionV3/AuxLogits/Conv2d_2b_1x1/biases"], container="", dtype=DT_FLOAT, shape=[6], shared_name="", _device="/device:GPU:0"]]

Traceback (most recent call last):
File "train_image_classifier.py", line 573, in
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train_image_classifier.py", line 569, in main
sync_optimizer=optimizer if FLAGS.sync_replicas else None)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/slim/python/slim/learning.py", line 742, in train
master, start_standard_services=False, config=session_config) as sess:
File "/usr/lib/python2.7/contextlib.py", line 17, in enter
return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 964, in managed_session
self.stop(close_summary_writer=close_summary_writer)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 792, in stop
stop_grace_period_secs=self._stop_grace_secs)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/coordinator.py", line 389, in join
six.reraise(*self._exc_info_to_raise)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 953, in managed_session
start_standard_services=start_standard_services)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/supervisor.py", line 708, in prepare_or_wait_for_session
init_feed_dict=self._init_feed_dict, init_fn=self._init_fn)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/session_manager.py", line 279, in prepare_session
sess.run(init_op, feed_dict=init_feed_dict)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 889, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1120, in _run
feed_dict_tensor, options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1317, in _do_run
options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1336, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation 'InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
[[Node: InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1 = VariableV2_class=["loc:@InceptionV3/AuxLogits/Conv2d_2b_1x1/biases"], container="", dtype=DT_FLOAT, shape=[6], shared_name="", _device="/device:GPU:0"]]

Caused by op u'InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1', defined at:
File "train_image_classifier.py", line 573, in
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "train_image_classifier.py", line 540, in main
global_step=global_step)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/optimizer.py", line 474, in apply_gradients
self._create_slots([_get_variable_for(v) for v in var_list])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/rmsprop.py", line 111, in _create_slots
self._zeros_slot(v, "momentum", self._name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/optimizer.py", line 796, in _zeros_slot
named_slots[_var_key(var)] = slot_creator.create_zeros_slot(var, op_name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/slot_creator.py", line 174, in create_zeros_slot
colocate_with_primary=colocate_with_primary)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/slot_creator.py", line 148, in create_slot_with_initializer
dtype)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/slot_creator.py", line 67, in _create_slot_var
validate_shape=validate_shape)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 1203, in get_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 1092, in get_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 425, in get_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 394, in _true_getter
use_resource=use_resource, constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 805, in _get_single_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 213, in init
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variables.py", line 309, in _init_from_args
name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/state_ops.py", line 133, in variable_op_v2
shared_name=shared_name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_state_ops.py", line 927, in _variable_v2
shared_name=shared_name, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1470, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.
[[Node: InceptionV3/AuxLogits/Conv2d_2b_1x1/biases/RMSProp_1 = VariableV2_class=["loc:@InceptionV3/AuxLogits/Conv2d_2b_1x1/biases"], container="", dtype=DT_FLOAT, shape=[6], shared_name="", _device="/device:GPU:0"]]

想问下第一章softmax回归的一个问题

softmax.py定义交叉熵的那行里面
cross_entropy = tf.reduce_mean(-tf.reduce_sum((y_ * tf.log(y))))
tf.reduce_sum函数在这里不用指明axis吗,不指明返回的是不是标量总和,怎么mean?
对python不太熟,麻烦指点一下

Fine tune 更多的层?

想请教一下 如何fine tune 更多的层 还有 如过换成其他的网络呢?
--checkpoint_path=satellite/pretrained/inception_v3.ckpt \ 这里我知道是加载之前训练好的模型权值
--checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \ 这里是不加载的层信息,但是这些信息是怎么来的,或者里面是说明代码,不太清楚。
--trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \如果换成其他网络是不是把“Inception”换成“Resnet”????
如果想fine tune 之前更多的层呢??
谢谢

第十二章的有代码部分失效

第十二章 BasicRNNCell和BasicLSTMCell已经失效,子类方法call也不能用了,应该是tensorflow更新了版本。目前还不确定有多少代码失效了,在测试中,能更改一下代码吗?谢谢

第三章目前遇到的几个问题

在训练的时候遇到的问题,都已经通过百度或者Google解决了,但是在验证模型测试的时候,报错了:
ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[100,64,147,147]
这个问题应该是空间不够了,我的GPU是GTX960 2Gb,按说应该是可以的,不知道有遇到此问题的吗?
另外一个问题是在到处pb文件的时候,产生如下错误:
INFO:tensorflow:Scale of 0 disables regularizer.
百度没查到相应的解决方法。

第3章TFrecord相关代码——python3的兼容性问题

小白刚入门,写在这里也是给自己做个记录。
1.range与xrange rage()在python3返回值不再是list,这里不改会报错;
2.TypeError: 'RGB' has type class 'str', but expected one of: (class 'bytes',)
两种改法:第一种参见https://stackoverflow.com/questions/38546672/inception-build-imagenet-data-py-typeerror-rgb-has-type-class-str-but-ex
第二种参见https://lixingcong.github.io/2016/03/06/convert-data-in-python/

chapter-自动上色

首先感谢博主的书,问下博主有训练好的食物上色和动漫上色的模型嘛。
穷学生买不起gpu,cpu训练要好久好久,@。@。动漫的估计要十几天。。。
还留着模型的话给个百度链接可好。

第五章目标检测

在research目录下执行model_builder_test.py时直接报错 No module named 'object_detection',请问大佬们有遇到吗?怎么解决呀

第17章python3上运行有几个地方需要改改

我搞了3个晚上终于才开始训练,在解压数据那里就被来来回回捣鼓了好多次,每次重新来就要等好久。
我把自己遇到的错误讲讲 希望对像我这样的新手小白有用吧,大神就不用看了。
1.首先在bazel这步 ,我是在研究室的服务器的子用户,不能用sudo,所以我是按bazel官网上方法下载安装的。

2.bazel-bin/im2txt/download_and_preprocess_mscoco "data/mscoco" 在使用这句的时候,如果你是子用户,必须把整个路径都写上
我现在的位置是im2txt文件夹,mkdir建立一个data文件夹,然后pwd,路径复制粘贴,然后复制粘贴/download_and_preprocess_mscoco "data/mscoco"

3.第二步那句话运行之后,下载数据解压完后会调用build_mscoco_data.py来处理数据。这个文件有3处要改。
1)所有的xrange改成range
2)第213行 with tf.gfile.FastGFile(image.filename, "r") as f:
"r"改成"rb"
3)第189行return tf.train.Feature(bytes_list=tf.train.BytesList(value=[str(value)]))
改成return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value.encode('utf-8') if type(value)==str else value]))

4.注意运行后面贴的那几句bazel-bin啥啥啥的 前面也必须贴全路径地址。

以上都是基于我是子用户,不知道root是不是就不用写_(:з」∠)_希望对后来者有用吧。

章节一readme错误

Deep-Learning-21-Examples/chapter_1/
1.2.2 两层卷积网络分类

python softmax_regression.py 这里错误了吧,应该是 python convolutional.py

部分章节使用了很多 TensorFlow 高级 API,不利于学习

比如,楼主在 15 章中使用了很多高级 API,学习性很差。一个很简答的时历曲线学习,搞得很复杂,很不直观。

from tensorflow.contrib.timeseries.python.timeseries import estimators as ts_estimators
from tensorflow.contrib.timeseries.python.timeseries import model as ts_model
from tensorflow.contrib.timeseries.python.timeseries import  NumpyReader

TF 的 API 设计的繁复、变动性大,手册也垃圾,实际工作项目中,也是使用的高级 API 吗?

第15章 运用LSTM进行单变量时序预测时遇到如下警告

如图,警告为
WARNING:tensorflow:Skipping summary for mean, must be a float, np.float32, np.int64, np.int32 or int or a serialized string of Summary.
WARNING:tensorflow:Skipping summary for observed, must be a float, np.float32, np.int64, np.int32 or int or a serialized string of Summary.
WARNING:tensorflow:Skipping summary for start_tuple, must be a float, np.float32, np.int64, np.int32 or int or a serialized string of Summary.
WARNING:tensorflow:Skipping summary for times, must be a float, np.float32, np.int64, np.int32 or int or a serialized string of Summary.
WARNING:tensorflow:Input graph does not use tf.data.Dataset or contain a QueueRunner. That means predict yields forever. This is probably a mistake.
请问如何解决?

第三章 转化为tfrecord格式错误

return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
TypeError: 'rock' has type str, but expected one of: bytes
您好,书是不错,可我用的python3.6 ,改了几处后还是有错,跑不了

第二章的tf.train.string_input_producer

tf.train.string_input_producer需要start_queue_runners来填充队列。
但是我在cifar10_train.py中没有找到start_queue_runners。
所以是我没有找到,还是有其他的方式来填充队列

第一章 在验证集上报告正确率 用的数据依然是训练集上的数据.

    batch = mnist.train.next_batch(50)
    # 每100步报告一次在验证集上的准确度
    if i % 100 == 0:
        train_accuracy = accuracy.eval(feed_dict={
            x: batch[0], y_: batch[1], keep_prob: 1.0})
        print("step %d, training accuracy %g" % (i, train_accuracy))

这样修改下就是在验证集上报告正确率:
#定义验证集
validate_data_x = mnist.validation.images
validate_data_y = mnist.validation.labels
# 训练20000步
for i in range(20000):
batch = mnist.train.next_batch(50)
# 每100步报告一次在验证集上的准确度
if i % 100 == 0:
train_accuracy = accuracy.eval(feed_dict={
x: validate_data_x, y_: validate_data_y, keep_prob: 1.0})
print("step %d, training accuracy %g" % (i, train_accuracy))

5.2.1 安装TensorFlow Object Detection API

前3步都是正确的 ,到了第4步执行“python object_detection/builders/model_builder_test.py”时,出现了
TypeError:new() got an unexpected keyword argument 'serialized_options'

10 undefined names in Chapter 20

flake8 testing of https://github.com/hzy46/Deep-Learning-21-Examples on Python 2.7.14

$ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics

./chapter_20/agents/_async.py:16:11: F821 undefined name 'DeepQ'
    super(DeepQ, self).__init__(sess, pred_network, target_network, env, stat, conf)
          ^
./chapter_20/agents/_async.py:83:29: F821 undefined name 'state'
      action = self.predict(state)
                            ^
./chapter_20/agents/_async.py:96:25: F821 undefined name 'ep'
                        ep, q, loss, is_update, self.learning_rate_op)
                        ^
./chapter_20/agents/_async.py:96:29: F821 undefined name 'q'
                        ep, q, loss, is_update, self.learning_rate_op)
                            ^
./chapter_20/agents/_async.py:96:32: F821 undefined name 'loss'
                        ep, q, loss, is_update, self.learning_rate_op)
                               ^
./chapter_20/agents/_async.py:96:38: F821 undefined name 'is_update'
                        ep, q, loss, is_update, self.learning_rate_op)
                                     ^
./chapter_20/agents/_n_step_q.py:15:11: F821 undefined name 'DeepQ'
    super(DeepQ, self).__init__(sess, pred_network, target_network, env, stat, conf)
          ^
./chapter_20/agents/_n_step_q.py:72:24: F821 undefined name 'global_var'
            global_v = global_var[re.sub(r'.*\/A3C_\d+\/', '', var.name)]
                       ^
./chapter_20/agents/_n_step_q.py:72:35: F821 undefined name 're'
            global_v = global_var[re.sub(r'.*\/A3C_\d+\/', '', var.name)]
                                  ^
./chapter_20/agents/_sarsa.py:16:11: F821 undefined name 'DeepQ'
    super(DeepQ, self).__init__(sess, pred_network, target_network, policy_network, env, stat, conf)
          ^
10    F821 undefined name 'DeepQ'
10

运行第七章代码报错

跑已经生成好的模型python eval.py --model_file models/wave.ckpt-done --image_file img/test.jpg
和跑训练模型 python train.py -c conf/wave.yml
都报这个错
Traceback (most recent call last):
File "eval.py", line 75, in
tf.app.run()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "eval.py", line 45, in main
generated = model.net(image, training=False)
File "/Users/yushiyang/project/Deep-Learning-21-Examples-master/chapter_7/model.py", line 100, in net
conv1 = relu(instance_norm(conv2d(image, 3, 32, 9, 1)))
File "/Users/yushiyang/project/Deep-Learning-21-Examples-master/chapter_7/model.py", line 9, in conv2d
x_padded = tf.pad(x, [[0, 0], [kernel / 2, kernel / 2], [kernel / 2, kernel / 2], [0, 0]], mode=mode)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 1738, in pad
tensor, paddings, mode="REFLECT", name=name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2580, in _mirror_pad
"MirrorPad", input=input, paddings=paddings, mode=mode, name=name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 609, in _apply_op_helper
param_name=input_name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 60, in _SatisfiesTypeConstraint
", ".join(dtypes.as_dtype(x).name for x in allowed_list)))
TypeError: Value passed to parameter 'paddings' has DataType float32 not in list of allowed values: int32, int64

21个项目玩转深度学习第5章 目标检测

根据该书的第5章的内容,对数据进行训练,我的电脑配置GTX 1080TI 12G+64 ubuntu16.04lts,在训练过程中,监测GPU使用情况,运行容量沾满,导致电脑关机。请问如何解决这个问题,我是新手,能不能说的详细点

第三章中python data_convert.py,出错,我用的是python3,windows下的,要如何改啊

INFO:root:Saving results to pic/
INFO:root:Determining list of input files and labels from pic/validation.
INFO:root:Finished finding files in 0 of 200 classes.
Traceback (most recent call last):
File "F:\algorithm\python3\21个项目玩转深度学习\Deep-Learning-21-Examples-master\chapter_3\data_prepare\data_convert.py", line 35, in
main(args)
File "F:\algorithm\python3\21个项目玩转深度学习\Deep-Learning-21-Examples-master\chapter_3\data_prepare\src\tfrecord.py", line 409, in main
command_args.validation_shards, command_args.labels_file, command_args)
File "F:\algorithm\python3\21个项目玩转深度学习\Deep-Learning-21-Examples-master\chapter_3\data_prepare\src\tfrecord.py", line 361, in _process_dataset
filenames, texts, labels = _find_image_files(directory, labels_file, command_args)
File "F:\algorithm\python3\21个项目玩转深度学习\Deep-Learning-21-Examples-master\chapter_3\data_prepare\src\tfrecord.py", line 341, in _find_image_files
random.shuffle(shuffled_index)
File "F:\Python36\lib\random.py", line 275, in shuffle
x[i], x[j] = x[j], x[i]
TypeError: 'range' object does not support item assignment

第一章关于在验证集上报告正确率

    batch = mnist.train.next_batch(50)

     if i % 100 == 0:
        train_accuracy = accuracy.eval(feed_dict={
            x: batch[0], y_: batch[1], keep_prob: 1.0})
        print("step %d, training accuracy %g" % (i, train_accuracy))

似乎并没有使用验证集,依然是在训练集上做的啊?

第三章训练模型遇到的问题,训练过程卡住了,模型一直是model.ckpt-0

运行第三章3.3.4节开始训练的命令后,开始一直卡在INFO:tensorflow:global_step/sec=0,一直重复输出,一段时间后,然后就一直卡在INFO:tensorflow:S**ing checkpoint to path satellite/train_dir/model.ckpt,隔一段时间这个就重复输出,但是训练文件夹里保存的模型一直是model.ckpt-0,请问是什么原因?

第七章的快速风格迁移

运行书上第一句命令时候报错如下:
TypeError: Value passed to parameter 'paddings' has DataType float32 not in list of allowed values: int32, int64,不知道怎么办。

Requirements:Hardware

Hi,
when training the data, the computer broke down. I guess the GPU memory is insufficient, so I want to know the Configuration requirements,

第三章,采用rennet_v1_50模型进行训练,已经训练完成,想导出模型对单张图像进行识别,最后的classfy_image_inception_v3.py出现错误,应该怎么修改

第三章,采用rennet_v1_50模型进行训练,已经训练完成,想导出模型对单张图像进行识别,最后的classfy_image_inception_v3.py出现错误,应该怎么修改呀?
KeyError: "The name 'resnet_v1/logits/SpatialSqueeze:0' refers to a Tensor which does not exist. The operation, 'resnet_v1/logits/SpatialSqueeze', does not exist in the graph."

第五章:深度学习中的目标检测

我的环境是win10,python3。在复现第五章的代码时,目前遇到了三个问题:
1:http://download.tensorflow.org登录不上,然后faster_rcnn_inception_resnet_v2_...那个模型我是通过其他博客找到的。
default
2:在运行train.py文件时
E:\Softwave\Anaconda\python.exe E:/Codes/Deep-Learning-21-Examples/Chapter_5/research/object_detection/train.py
Traceback (most recent call last):
File "E:/Codes/Deep-Learning-21-Examples/Chapter_5/research/object_detection/train.py", line 202, in
tf.app.run()
File "E:\Softwave\Anaconda\lib\site-packages\tensorflow\python\platform\app.py", line 124, in run
_sys.exit(main(argv))
File "E:/Codes/Deep-Learning-21-Examples/Chapter_5/research/object_detection/train.py", line 198, in main
worker_job_name, is_chief, FLAGS.train_dir)
File "E:/Codes/Deep-Learning-21-Examples/Chapter_5/research\object_detection\trainer.py", line 161, in train
detection_model = create_model_fn()
File "E:/Codes/Deep-Learning-21-Examples/Chapter_5/research\object_detection\builders\model_builder.py", line 77, in build
return _build_faster_rcnn_model(model_config.faster_rcnn, is_training)
File "E:/Codes/Deep-Learning-21-Examples/Chapter_5/research\object_detection\builders\model_builder.py", line 218, in _build_faster_rcnn_model
first_stage_only = frcnn_config.first_stage_only
AttributeError: 'FasterRcnn' object has no attribute 'first_stage_only'

Process finished with exit code 1
default

然后我的做法是将model_bulider.py文件第218和第222行改为了first_stage_only =False
3:在修改为first_stage_only =False后,运行train.py文件后: File "E:\Softwave\Anaconda\lib\site-packages\tensorflow\python\framework\tensor_util.py", line 328, in _AssertCompatible
(dtype.name, repr(mismatch), type(mismatch).name))
TypeError: Expected string, got ['VOC/pet_train.record'] of type 'RepeatedScalarFieldContainer' instead.
default

default
请问我该如何修改呢。。。
在复现时遇到 了各种奇怪的问题,度娘谷歌了好久,本以为终于可以了,没想到。。。。。。

softmax_regression中批量梯度下降问题

写代码时,增加一个epoch的循环,最后的结果只有0.86。为什么大神里面就可以达到0.9多?

for step in range(500):
    x,y = mnist.train.next_batch(batch_size)
    for i in range(num):#num = mnist.train.num_examples/batch_size
        _,tmp = sess.run([optimizer,loss],{X:x,Y:y}) #optimizer=Adam.minimize(loss)
    #sess.run(optimizer,{X:x,Y:y})

print("training accuracy",accuracy.eval({X:mnist.train.images,Y:mnist.train.labels}))

第八章,生成MNIST图像

Traceback (most recent call last):
File "main.py", line 103, in
tf.app.run()
File "D:\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tensorflow\python\platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "main.py", line 65, in main
data_dir=FLAGS.data_dir)
File "D:\pyproject\study_TF_for21\chapter8\model.py", line 75, in init
self.data_X, self.data_y = self.load_mnist()
File "D:\pyproject\study_TF_for21\chapter8\model.py", line 468, in load_mnist
trX = loaded[16:].reshape((60000,28,28,1)).astype(np.float)
ValueError: cannot reshape array of size 9912406 into shape (60000,28,28,1)

这个怎么解决。。。windows环境

scipy.misc.toimage API新版已经被弃用

这里 https://github.com/hzy46/Deep-Learning-21-Examples/blob/master/chapter_1/save_pic.py#L25 使用的 API 已经被弃用

https://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.toimage.html#scipy-misc-toimage
toimage is deprecated! toimage is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use Pillow’s Image.fromarray directly instead.

这样是可以的

from PIL import Image
Image.fromarray((image_array*256).astype(np.uint8)).save(filename)

第五章:目标检测中的边框回归

看到从R-CNN到faster-rcnn都用到边框回归,其中边框回归的损失函数不理解
网上的一篇博客https://blog.csdn.net/zijin0802034/article/details/77685438
讲的是RCNN的边框回归损失函数的求法,其中Φ5(P)是输入 Proposal 的特征向量,,也就是 R-CNN 中的 Pool5 feature(特征向量),wT是要学习的参数,就是RCNN中边框回归部分全连接层的参数
预测的目标可以表示为 d∗(P)=wT∗Φ5(P),

对于faster-rcnn在前面公共卷积部分提取的feature map 经过一个3* 3卷积后产生anchor,然后在接1 *1卷积核得到proposal,

问题1:但是对于faster-rcnn来说Φ5(P)是什么
问题2:但是对于faster-rcnn来说wT是谁的参数呢

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.