Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_dota.py ValueError: Shape must be rank 0 but is rank 1 for 'cond/cond/Switch' (op: 'Switch') with input shapes: [6], [6]. #33

Open
programmer1401 opened this issue Mar 29, 2021 · 8 comments

Comments

@programmer1401
Copy link

when I run test_dota.py, it occurred ValueError: Shape must be rank 0 but is rank 1 for 'cond/cond/Switch' (op: 'Switch') with input shapes: [6], [6].
what can I do?

thank you so much for your help!

@HsLOL
Copy link

HsLOL commented Mar 29, 2021

I have the similar problem

@HsLOL
Copy link

HsLOL commented Mar 30, 2021

@programmer1401
我感觉好像与配置文件有关,当我换了cfg.py中的内容后,这个问题就没了,但是又遇到了其他的问题,刚入门这个,感觉这个工程很大,没有头绪...

@programmer1401
Copy link
Author

@programmer1401
我感觉好像与配置文件有关,当我换了cfg.py中的内容后,这个问题就没了,但是又遇到了其他的问题,刚入门这个,感觉这个工程很大,没有头绪...

谢谢提醒!我把test_dota_ms.py中324行左右的--multi_scale的值改变以后,可以正常运行了!(但是不知道原因)

@HsLOL
Copy link

HsLOL commented Apr 2, 2021

@programmer1401
我感觉好像与配置文件有关,当我换了cfg.py中的内容后,这个问题就没了,但是又遇到了其他的问题,刚入门这个,感觉这个工程很大,没有头绪...

谢谢提醒!我把test_dota_ms.py中324行左右的--multi_scale的值改变以后,可以正常运行了!(但是不知道原因)

请问您是怎么改的呢?可以发我一份正常运行的代码和测试图片吗?
我的邮箱是18310699587@163.com

谢谢!

@programmer1401
Copy link
Author

programmer1401 commented Apr 5, 2021

@programmer1401
我感觉好像与配置文件有关,当我换了cfg.py中的内容后,这个问题就没了,但是又遇到了其他的问题,刚入门这个,感觉这个工程很大,没有头绪...

谢谢提醒!我把test_dota_ms.py中324行左右的--multi_scale的值改变以后,可以正常运行了!(但是不知道原因)

请问您是怎么改的呢?可以发我一份正常运行的代码和测试图片吗?
我的邮箱是18310699587@163.com

谢谢!

我是用服务器运行的文件,所以没有显示测试图像(不知道如何在服务器显示)。
服务器最近不能用了,所以也没办法截图了,输出文件也在服务器上……

下面是代码:
test_dota_ms.zip

@HsLOL
Copy link

HsLOL commented Apr 10, 2021

@programmer1401
我感觉好像与配置文件有关,当我换了cfg.py中的内容后,这个问题就没了,但是又遇到了其他的问题,刚入门这个,感觉这个工程很大,没有头绪...

谢谢提醒!我把test_dota_ms.py中324行左右的--multi_scale的值改变以后,可以正常运行了!(但是不知道原因)

请问您是怎么改的呢?可以发我一份正常运行的代码和测试图片吗?
我的邮箱是18310699587@163.com
谢谢!

我是用服务器运行的文件,所以没有显示测试图像(不知道如何在服务器显示)。
服务器最近不能用了,所以也没办法截图了,输出文件也在服务器上……

下面是代码:
test_dota_ms.zip

好的,谢谢!

@programmer1401
Copy link
Author

programmer1401 commented Apr 13, 2021

不知道是否能通过修改参数的方式使程序正常运行,最近好像发现了出错的根本原因,希望能对你有用!
运行 test_dota_ms.py 报错时,出现问题的地方是读取数据的位置
img_batch = short_side_resize_for_inference_data(img_tensor=img_batch, target_shortside_len=cfgs.IMG_SHORT_SIDE_LEN, length_limitation=cfgs.IMG_MAX_LENGTH, is_resize=not args.multi_scale)

在训练文件 multi_gpu_train.py 中同样也有读取数据的函数:
img_name_batch, img_batch, gtboxes_and_label_batch, num_objects_batch, img_h_batch, img_w_batch = \ next_batch(dataset_name=cfgs.DATASET_NAME, batch_size=cfgs.BATCH_SIZE * num_gpu, shortside_len=shortside_len, is_training=True)

对比了两个函数,发现 target_shortside_lenshortside_len 两个参数的值不一样

返回训练文件 multi_gpu_train.py ,发现了如下代码:
if cfgs.IMAGE_PYRAMID: shortside_len_list = tf.constant(cfgs.IMG_SHORT_SIDE_LEN) shortside_len = tf.random_shuffle(shortside_len_list)[0] else: shortside_len = cfgs.IMG_SHORT_SIDE_LEN

这就是问题所在! cfgs.IMAGE_PYRAMID 的默认值为 True,
训练时 shortside_len = tf.random_shuffle(shortside_len_list)[0];
而测试时,shortside_len 设为了 cfgs.IMG_SHORT_SIDE_LEN,所以出现了 ValueError: Shape must be rank 0 but is rank 1 for 'cond/cond/Switch' (op: 'Switch') with input shapes: [6], [6].

改正的方法很简单,把 test_dota_ms.py 中 shortside_len 的值改变就可以了!

ps: 如果在运行 read_tfrecord_multi_gpu.py 时也出现了同样的问题,可以采用同样的方法解决!

@HsLOL
Copy link

HsLOL commented Apr 16, 2021

不知道是否能通过修改参数的方式使程序正常运行,最近好像发现了出错的根本原因,希望能对你有用!
运行 test_dota_ms.py 报错时,出现问题的地方是读取数据的位置
img_batch = short_side_resize_for_inference_data(img_tensor=img_batch, target_shortside_len=cfgs.IMG_SHORT_SIDE_LEN, length_limitation=cfgs.IMG_MAX_LENGTH, is_resize=not args.multi_scale)

在训练文件 multi_gpu_train.py 中同样也有读取数据的函数:
img_name_batch, img_batch, gtboxes_and_label_batch, num_objects_batch, img_h_batch, img_w_batch = \ next_batch(dataset_name=cfgs.DATASET_NAME, batch_size=cfgs.BATCH_SIZE * num_gpu, shortside_len=shortside_len, is_training=True)

对比了两个函数,发现 target_shortside_lenshortside_len 两个参数的值不一样

返回训练文件 multi_gpu_train.py ,发现了如下代码:
if cfgs.IMAGE_PYRAMID: shortside_len_list = tf.constant(cfgs.IMG_SHORT_SIDE_LEN) shortside_len = tf.random_shuffle(shortside_len_list)[0] else: shortside_len = cfgs.IMG_SHORT_SIDE_LEN

这就是问题所在! cfgs.IMAGE_PYRAMID 的默认值为 True,
训练时 shortside_len = tf.random_shuffle(shortside_len_list)[0];
而测试时,shortside_len 设为了 cfgs.IMG_SHORT_SIDE_LEN,所以出现了 ValueError: Shape must be rank 0 but is rank 1 for 'cond/cond/Switch' (op: 'Switch') with input shapes: [6], [6].

改正的方法很简单,把 test_dota_ms.py 中 shortside_len 的值改变就可以了!

ps: 如果在运行 read_tfrecord_multi_gpu.py 时也出现了同样的问题,可以采用同样的方法解决!

不知道是否能通过修改参数的方式使程序正常运行,最近好像发现了出错的根本原因,希望能对你有用!
运行 test_dota_ms.py 报错时,出现问题的地方是读取数据的位置
img_batch = short_side_resize_for_inference_data(img_tensor=img_batch, target_shortside_len=cfgs.IMG_SHORT_SIDE_LEN, length_limitation=cfgs.IMG_MAX_LENGTH, is_resize=not args.multi_scale)

在训练文件 multi_gpu_train.py 中同样也有读取数据的函数:
img_name_batch, img_batch, gtboxes_and_label_batch, num_objects_batch, img_h_batch, img_w_batch = \ next_batch(dataset_name=cfgs.DATASET_NAME, batch_size=cfgs.BATCH_SIZE * num_gpu, shortside_len=shortside_len, is_training=True)

对比了两个函数,发现 target_shortside_lenshortside_len 两个参数的值不一样

返回训练文件 multi_gpu_train.py ,发现了如下代码:
if cfgs.IMAGE_PYRAMID: shortside_len_list = tf.constant(cfgs.IMG_SHORT_SIDE_LEN) shortside_len = tf.random_shuffle(shortside_len_list)[0] else: shortside_len = cfgs.IMG_SHORT_SIDE_LEN

这就是问题所在! cfgs.IMAGE_PYRAMID 的默认值为 True,
训练时 shortside_len = tf.random_shuffle(shortside_len_list)[0];
而测试时,shortside_len 设为了 cfgs.IMG_SHORT_SIDE_LEN,所以出现了 ValueError: Shape must be rank 0 but is rank 1 for 'cond/cond/Switch' (op: 'Switch') with input shapes: [6], [6].

改正的方法很简单,把 test_dota_ms.py 中 shortside_len 的值改变就可以了!

ps: 如果在运行 read_tfrecord_multi_gpu.py 时也出现了同样的问题,可以采用同样的方法解决!

谢谢您的建议~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants