duanshengliu / End-to-end-for-chinese-plate-recognition

基于u-net,cv2以及cnn的中文车牌定位,矫正和端到端识别软件,其中unet和cv2用于车牌定位和矫正,cnn进行车牌识别,unet和cnn都是基于tensorflow的keras实现
Apache License 2.0
517 stars 118 forks source link

报错ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray) #21

Closed yyamx closed 10 months ago

yyamx commented 2 years ago

如何解决错误

duanshengliu commented 2 years ago

贴一下具体的代码,不然不知道是什么情况

yyamx commented 2 years ago

贴一下具体的代码,不然不知道是什么情况

File "E:\End-to-end-for-chinese-plate-recognition-master\License-plate-recognition\Unet.py", line 96, in unet_train model.fit(X_train, y_train, epochs=100, batch_size=15)#epochs和batch_size看个人情况调整,batch_size不要过大,否则内存容易溢出 File "D:\anaconda3\envs\pytorch\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "D:\anaconda3\envs\pytorch\lib\site-packages\tensorflow\python\framework\constant_op.py", line 102, in convert_to_eager_tensor return ops.EagerTensor(value, ctx.device_name, dtype) ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).

duanshengliu commented 2 years ago

你的TF版本是多少,是2.x吗?

yyamx commented 2 years ago

你的TF版本是多少,是2.x吗?

是的 2.8,必须降低版本嘛

duanshengliu commented 2 years ago

你的TF版本是多少,是2.x吗?

是的 2.8,必须降低版本嘛

我之前训练用的是TF1.15,你可以试一下

yyamx commented 2 years ago

Traceback (most recent call last): File "E:/End-to-end-for-chinese-plate-recognition-master/License-plate-recognition/train.py", line 6, in unet_train()#训练后得到unet.h5,用于车牌定位 File "E:\End-to-end-for-chinese-plate-recognition-master\License-plate-recognition\Unet.py", line 96, in unet_train model.fit(X_train, y_train, epochs=100, batch_size=15)#epochs和batch_size看个人情况调整,batch_size不要过大,否则内存容易溢出 File "D:\anaconda3\envs\hyperlpr36\lib\site-packages\tensorflow\contrib\keras\python\keras\engine\training.py", line 1406, in fit batch_size=batch_size) File "D:\anaconda3\envs\hyperlpr36\lib\site-packages\tensorflow\contrib\keras\python\keras\engine\training.py", line 1300, in _standardize_user_data exception_prefix='model input') File "D:\anaconda3\envs\hyperlpr36\lib\site-packages\tensorflow\contrib\keras\python\keras\engine\training.py", line 138, in _standardize_input_data ' dimensions, but got array with shape ' + str(array.shape)) ValueError: Error when checking model input: expected input_1 to have 4 dimensions, but got array with shape (2475, 1) 更改之后的错误,这个如何解决

duanshengliu commented 2 years ago

Traceback (most recent call last): File "E:/End-to-end-for-chinese-plate-recognition-master/License-plate-recognition/train.py", line 6, in unet_train()#训练后得到unet.h5,用于车牌定位 File "E:\End-to-end-for-chinese-plate-recognition-master\License-plate-recognition\Unet.py", line 96, in unet_train model.fit(X_train, y_train, epochs=100, batch_size=15)#epochs和batch_size看个人情况调整,batch_size不要过大,否则内存容易溢出 File "D:\anaconda3\envs\hyperlpr36\lib\site-packages\tensorflow\contrib\keras\python\keras\engine\training.py", line 1406, in fit batch_size=batch_size) File "D:\anaconda3\envs\hyperlpr36\lib\site-packages\tensorflow\contrib\keras\python\keras\engine\training.py", line 1300, in _standardize_user_data exception_prefix='model input') File "D:\anaconda3\envs\hyperlpr36\lib\site-packages\tensorflow\contrib\keras\python\keras\engine\training.py", line 138, in _standardize_input_data ' dimensions, but got array with shape ' + str(array.shape)) ValueError: Error when checking model input: expected input_1 to have 4 dimensions, but got array with shape (2475, 1) 更改之后的错误,这个如何解决

我刚刚使用TF2.8测试了没有问题,可以训练,你的数据集是图片吗,shape不对?

yyamx commented 2 years ago

是的Img是jpg格式,label是png格式,大小必须是512?我可否直接改成320

yyamx commented 2 years ago

训练图片大小有要求没

duanshengliu commented 2 years ago

是的Img是jpg格式,label是png格式,大小必须是512?我可否直接改成320

是的,需要512*512的

yyamx commented 2 years ago

是的Img是jpg格式,label是png格式,大小必须是512?我可否直接改成320

是的,需要512*512的

就是说训练之前的数据集准备中就必须把它reshape成512x512的,我要是想320x320的话,具体的unet网络代码是否需要修改

duanshengliu commented 2 years ago

是的Img是jpg格式,label是png格式,大小必须是512?我可否直接改成320

是的,需要512*512的

就是说训练之前的数据集准备中就必须把它reshape成512x512的,我要是想320x320的话,具体的unet网络代码是否需要修改 是的