目錄
問題一:module object has no attribute v1
問題二:module object has no attribute 'gfile'
問題三:module object has no attribute resize
問題一:module object has no attribute v1
Traceback (most recent call last):
File "./remove_gt_colormap.py", line 32, in <module>
tf.compat.v1.flags.DEFINE_string('original_gt_folder',
AttributeError: 'module' object has no attribute 'v1'
解決辦法:
找到出錯的地方,將tf.compat.v1.flag.DEFINE_string改成tf.flag.DEFINE_string就行了,當然文中可能有好幾處用的compat.v1,一併刪掉就好了。
問題二:module object has no attribute 'gfile'
File "./remove_gt_colormap.py", line 84, in <module>
tf.app.run()
File "/home/gaoye/.local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "./remove_gt_colormap.py", line 69, in main
if not tf.io.gfile.isdir(FLAGS.output_dir):
AttributeError: 'module' object has no attribute 'gfile'
解決辦法:
找到出錯的地方,將tf.io.gfile.isdir改成tf.gfile.isdir,但這時候仍然會報錯module objecct has no attribute isdir,這是因爲tensorflow1中沒有isdir,將其改稱tf.gfile.Exists即可。將代碼中tf.io.gfile.XXX中的io都刪掉,可能還會報錯has no attribute makedirs 之類的問題,那是因爲tensorflow1和tensorflow2版本對應的名字不太一樣,比如tensorflow1中makedirs是MakeDirs。下面貼上對比,一一對應照着修改就可以。
Tensorflow 1 的gfile API介紹 https://blog.csdn.net/a373595475/article/details/79693430
Tensorflw 2 的gfile API介紹 https://zhuanlan.zhihu.com/p/85130507
問題三:module object has no attribute resize
AttributeError: module tensorflow.image has no attribute resize
解決辦法:
找到出錯的地方,將tf.image.resize()改成tf.image.resize_images()
e.g.
label = tf.image.resize(label,new_dim,method=get_label_resize_method(label),align_corners=True)
改成
label = tf.image.resize_images(label,new_dim,method=get_label_resize_method(label),align_corners=True)
若resize函數指明瞭method,比如插值,還可以用以下方式解決:
label = tf.image.resize(label,new_dim,method='bilinear',align_corners=True)
改成
label = tf.image.resize_bilinear(label,new_dim,align_corners=True)
resize_images是總的接口,建議用resize_images,便於維護。
Tensorflow中image.resize API介紹:https://www.jianshu.com/p/9cccdb418674
碎碎念:其實這就是tensorflow 1.X版本和tensorflow2.X版本的區別(真是奇怪,官方deeplab代碼,用tensorflow2跑會出問題,用tensorflow1又在標籤處理代碼那出版本問題。。。爲啥就不統一一個版本呢,心累)