MaybeShewill-CV / CRNN_Tensorflow

Convolutional Recurrent Neural Networks(CRNN) for Scene Text Recognition
MIT License
1.03k stars 388 forks source link

我在改成单通道训练时发生了以下错误 #323

Closed LXLun closed 5 years ago

LXLun commented 5 years ago

I0728 17:38:33.145712 108486 train_shadownet.py:577] Use single gpu to train the model (32, 32, 280, 1) SparseTensor(indices=Tensor("DeserializeSparse:0", shape=(?, 2), dtype=int64), values=Tensor("DeserializeSparse:1", shape=(?,), dtype=int32), dense_shape=Tensor("DeserializeSparse:2", shape=(2,), dtype=int64)) Tensor("train_IteratorGetNext:2", shape=(32,), dtype=string)

此处为train_images.shape

2019-07-28 17:38:35.654972: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA 2019-07-28 17:38:36.331570: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1432] Found device 0 with properties: name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.6575 pciBusID: 0000:65:00.0 totalMemory: 10.91GiB freeMemory: 10.76GiB 2019-07-28 17:38:36.331610: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1511] Adding visible gpu devices: 0 2019-07-28 17:38:36.580262: I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] Device interconnect StreamExecutor with strength 1 edge matrix: 2019-07-28 17:38:36.580309: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988] 0 2019-07-28 17:38:36.580318: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0: N 2019-07-28 17:38:36.580507: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10058 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:65:00.0, compute capability: 6.1) I0728 17:38:36.776176 108486 train_shadownet.py:275] Training from scratch Traceback (most recent call last): File "/home/luoxilun/lxl_new/train_venv/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1334, in _do_call return fn(*args) File "/home/luoxilun/lxl_new/train_venv/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1319, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "/home/luoxilun/lxl_new/train_venv/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1407, in _call_tf_sessionrun run_metadata) tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 860160 values, but the requested shape has 286720 [[{{node Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](Cast, Reshape/shape)]] [[{{node val_IteratorGetNext}} = IteratorGetNextoutput_shapes=[[32,32,280,1], , [32]], output_types=[DT_FLOAT, DT_VARIANT, DT_STRING], _device="/job:localhost/replica:0/task:0/device:CPU:0"]] [[{{node shadow_net/sequence_rnn_module/stack_bidirectional_rnn/cell_1/bidirectional_rnn/fw/fw/while/Less/_32}} = _HostSendT=DT_BOOL, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_374_s...while/Less", _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "tools/train_shadownet.py", line 583, in need_decode=args.decode_outputs File "tools/train_shadownet.py", line 329, in train_shadownet [optimizer, train_ctc_loss, merge_summary_op]) File "/home/luoxilun/lxl_new/train_venv/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run run_metadata_ptr) File "/home/luoxilun/lxl_new/train_venv/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1152, in _run feed_dict_tensor, options, run_metadata) File "/home/luoxilun/lxl_new/train_venv/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1328, in _do_run run_metadata) File "/home/luoxilun/lxl_new/train_venv/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1348, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: Input to reshape is a tensor with 860160 values, but the requested shape has 286720 [[{{node Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](Cast, Reshape/shape)]] [[node val_IteratorGetNext (defined at /home/luoxilun/lxl_new/CRNN_Tensorflow-master/data_provider/tf_io_pipline_fast_tools.py:409) = IteratorGetNextoutput_shapes=[[32,32,280,1], , [32]], output_types=[DT_FLOAT, DT_VARIANT, DT_STRING], _device="/job:localhost/replica:0/task:0/device:CPU:0"]] [[{{node shadow_net/sequence_rnn_module/stack_bidirectional_rnn/cell_1/bidirectional_rnn/fw/fw/while/Less/_32}} = _HostSendT=DT_BOOL, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_374_s...while/Less", _device="/job:localhost/replica:0/task:0/device:GPU:0"]]

我修改了配置文件中的

Number of channels in images

__C.ARCH.INPUT_CHANNELS = 1

以及读取图片是直接读取成灰度图

image = cv2.imread(sample_path, cv2.IMREAD_GRAYSCALE) if image is None: continue image = cv2.resize(image, dsize=tuple(CFG.ARCH.INPUT_SIZE), interpolation=cv2.IMREAD_GRAYSCALE)

但是训练时产生了上面的错误

LXLun commented 5 years ago

三通道图片识别时间太长,对效率影响较大

MaybeShewill-CV commented 5 years ago

@LXLun cv2.resize(image, dsize=tuple(CFG.ARCH.INPUT_SIZE), interpolation=cv2.IMREAD_GRAYSCALE) 建议你多看点基础只是 IMREAD_GRAYSCALE不是插值方法