Python Tensorflow估计器:自定义输入\u fn不工作

Python Tensorflow估计器:自定义输入\u fn不工作,python,tensorflow,machine-learning,deep-learning,convolutional-neural-network,Python,Tensorflow,Machine Learning,Deep Learning,Convolutional Neural Network,我正在读Tensorflow的《建立我的第一个CNN》。原始代码运行得非常好。然而,当我尝试使用自己的输入函数而不是原始的tf.estimator.inputs.numpy\u input\u fn时,我遇到了一个问题 我的代码如下,类似于: 但是,当我运行该代码时,Tensorflow在将以下内容打印到console后卡住了: INFO:tensorflow:Using config: {'_is_chief': True, '_task_type': 'worker', '_save_che

我正在读Tensorflow的《建立我的第一个CNN》。原始代码运行得非常好。然而,当我尝试使用自己的输入函数而不是原始的
tf.estimator.inputs.numpy\u input\u fn时,我遇到了一个问题

我的代码如下,类似于:

但是,当我运行该代码时,Tensorflow在将以下内容打印到console后卡住了:

INFO:tensorflow:Using config: {'_is_chief': True, '_task_type': 'worker', '_save_checkpoints_secs': 600, '_task_id': 0, '_save_summary_steps': 10, '_keep_checkpoint_every_n_hours': 10000, '_master': '', '_evaluation_master': '', '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x00000217B16B64E0>, '_tf_random_seed': None, '_session_config': None, '_log_step_count_steps': 100, '_keep_checkpoint_max': 5, '_global_id_in_cluster': 0, '_model_dir': './model', '_num_ps_replicas': 0, '_num_worker_replicas': 1, '_save_checkpoints_steps': None}
WARNING:tensorflow:Estimator's model_fn (<function cnn_model_fn at 0x000002179C3231E0>) includes params argument, but params are not passed to Estimator.
INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Graph was finalized.
2018-04-13 11:23:31.303380: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-04-13 11:23:32.071305: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1344] Found device 0 with properties: 
name: GeForce GTX 960M major: 5 minor: 0 memoryClockRate(GHz): 1.0975
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.65GiB
2018-04-13 11:23:32.071834: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1423] Adding visible gpu devices: 0
2018-04-13 11:23:33.064563: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-04-13 11:23:33.064904: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:917]      0 
2018-04-13 11:23:33.065131: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:930] 0:   N 
2018-04-13 11:23:33.065460: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1041] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1420 MB memory) -> physical GPU (device: 0, name: GeForce GTX 960M, pci bus id: 0000:01:00.0, compute capability: 5.0)
INFO:tensorflow:Restoring parameters from ./model\model.ckpt-800
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.
INFO:tensorflow:使用配置:{“你是负责人”:对,“任务类型”:“工人”,“保存检查点”:“600”,“任务id”:“0”,“保存摘要”步骤:10,“保存检查点每小时”:10000,“保存主控点”:“评估主控点”:“服务”:无”,“集群规格”:“无”,“随机种子”:无”,“会话配置”:无”,“日志步骤计数”:100,“保存检查点”:最大5集群中的al_id_:0,“_model_dir':”./model',“_num_ps_replications”:0,“_num_worker_replications”:1,“_save_checkpoints_steps”:无}
警告:tensorflow:Estimator的模型_fn()包含参数参数,但参数未传递给Estimator。
信息:tensorflow:正在调用模型\u fn。
信息:tensorflow:已完成调用模型\u fn。
信息:tensorflow:创建检查点SaveRhook。
信息:tensorflow:图表已定稿。
2018-04-13 11:23:31.303380:it:\src\github\tensorflow\tensorflow\core\platform\cpu\u feature\u guard.cc:140]您的cpu支持此tensorflow二进制文件未编译使用的指令:AVX2
2018-04-13 11:23:32.071305:it:\src\github\tensorflow\tensorflow\core\common\u runtime\gpu\gpu\device.cc:1344]找到了具有以下属性的设备0:
名称:GeForce GTX 960M主调:5小调:0内存锁定速率(GHz):1.0975
pciBusID:0000:01:00.0
总内存:2.00GiB自由内存:1.65GiB
2018-04-13 11:23:32.071834:IT:\src\github\tensorflow\tensorflow\core\common\u runtime\gpu\gpu\device.cc:1423]添加可见gpu设备:0
2018-04-13 11:23:33.064563:it:\src\github\tensorflow\tensorflow\core\common\u runtime\gpu\gpu\device.cc:911]具有强度1边缘矩阵的设备互连流执行器:
2018-04-13 11:23:33.064904:it:\src\github\tensorflow\tensorflow\core\common\u runtime\gpu\gpu\device.cc:917]0
2018-04-13 11:23:33.065131:it:\src\github\tensorflow\tensorflow\core\common\u runtime\gpu\gpu\device.cc:930]0:N
2018-04-13 11:23:33.065460:it:\src\github\tensorflow\tensorflow\core\common\u runtime\gpu\gpu\gpu device.cc:1041]创建了tensorflow设备(/job:localhost/replica:0/task:0/device:gpu:0,内存1420MB)->物理gpu(设备:0,名称:GeForce GTX 960M,pci总线id:0000:01:00.0,计算能力:5.0)
信息:tensorflow:从./model\model.ckpt-800恢复参数
信息:tensorflow:正在运行本地初始化操作。
信息:tensorflow:已完成运行本地初始化操作。
在那之后,Tensorflow既没有参加培训也没有退出,这太令人讨厌了

现在我猜在每个训练步骤中,它都会调用一次
train\u input\u fn
。由于该函数将洗牌整个MNIST数据集,因此计算效率可能会很低

为了验证我的想法,我尝试将数据集的大小从60000缩小到100,代码运行得非常好


那么这个问题的解决方案是什么呢?如何编写自定义输入函数而不出现此类问题?我希望有人能就此提供一些指导。

您能用一个完整的、自包含的示例来更新这个问题吗?(例如,使用随机NumPy数组而不是训练数据,以及一个虚拟模型函数。)另外,您是如何缩小数据集大小的?
INFO:tensorflow:Using config: {'_is_chief': True, '_task_type': 'worker', '_save_checkpoints_secs': 600, '_task_id': 0, '_save_summary_steps': 10, '_keep_checkpoint_every_n_hours': 10000, '_master': '', '_evaluation_master': '', '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x00000217B16B64E0>, '_tf_random_seed': None, '_session_config': None, '_log_step_count_steps': 100, '_keep_checkpoint_max': 5, '_global_id_in_cluster': 0, '_model_dir': './model', '_num_ps_replicas': 0, '_num_worker_replicas': 1, '_save_checkpoints_steps': None}
WARNING:tensorflow:Estimator's model_fn (<function cnn_model_fn at 0x000002179C3231E0>) includes params argument, but params are not passed to Estimator.
INFO:tensorflow:Calling model_fn.
INFO:tensorflow:Done calling model_fn.
INFO:tensorflow:Create CheckpointSaverHook.
INFO:tensorflow:Graph was finalized.
2018-04-13 11:23:31.303380: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-04-13 11:23:32.071305: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1344] Found device 0 with properties: 
name: GeForce GTX 960M major: 5 minor: 0 memoryClockRate(GHz): 1.0975
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.65GiB
2018-04-13 11:23:32.071834: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1423] Adding visible gpu devices: 0
2018-04-13 11:23:33.064563: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:911] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-04-13 11:23:33.064904: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:917]      0 
2018-04-13 11:23:33.065131: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:930] 0:   N 
2018-04-13 11:23:33.065460: I T:\src\github\tensorflow\tensorflow\core\common_runtime\gpu\gpu_device.cc:1041] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1420 MB memory) -> physical GPU (device: 0, name: GeForce GTX 960M, pci bus id: 0000:01:00.0, compute capability: 5.0)
INFO:tensorflow:Restoring parameters from ./model\model.ckpt-800
INFO:tensorflow:Running local_init_op.
INFO:tensorflow:Done running local_init_op.