好看的人Debug 的一天

有些话、适合烂在心里 提交于 2020-01-15 03:30:32

问题1:

  File "train.py", line 144, in <module>
    main()
  File "train.py", line 105, in main
    templete_model = models.init_model(args.Backbone,input_tensor)
  File "/mnt/ailab_data/17_bk/wsw/bcs_project/code/BCS-tf/kerasbcs/models/__init__.py", line 25, in init_model
    return __model_factory[name](*args, **kwargs)
  File "/mnt/ailab_data/17_bk/wsw/bcs_project/code/BCS-tf/kerasbcs/models/Efficientnet.py", line 20, in Efficientnet_all
    x = GlobalAveragePooling2D()(x)
  File "/home/ailab/anaconda3/envs/tf1.14/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 663, in __call__
    inputs, outputs, args, kwargs)
  File "/home/ailab/anaconda3/envs/tf1.14/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1708, in _set_connectivity_metadata_
    input_tensors=inputs, output_tensors=outputs, arguments=kwargs)
  File "/home/ailab/anaconda3/envs/tf1.14/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1795, in _add_inbound_node
    input_tensors)
  File "/home/ailab/anaconda3/envs/tf1.14/lib/python3.6/site-packages/tensorflow/python/util/nest.py", line 515, in map_structure
    structure[0], [func(*x) for x in entries],
  File "/home/ailab/anaconda3/envs/tf1.14/lib/python3.6/site-packages/tensorflow/python/util/nest.py", line 515, in <listcomp>
    structure[0], [func(*x) for x in entries],
  File "/home/ailab/anaconda3/envs/tf1.14/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1794, in <lambda>
    inbound_layers = nest.map_structure(lambda t: t._keras_history.layer,

解决方法:将keras的版本升级到keras2.2.4吧!


问题2:

Error when running tensorflow in virtualenv: module ‘tensorflow’ has no attribute ‘truncated_normal’

  File "/home/ailab/anaconda3/envs/tf/lib/python3.6/site-packages/keras/engine/base_layer.py", line 249, in add_weight
    weight = K.variable(initializer(shape),
  File "/home/ailab/anaconda3/envs/tf/lib/python3.6/site-packages/keras/initializers.py", line 214, in __call__
    dtype=dtype, seed=self.seed)
  File "/home/ailab/anaconda3/envs/tf/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 4185, in truncated_normal
    return tf.truncated_normal(shape, mean, stddev, dtype=dtype, seed=seed)
AttributeError: module 'tensorflow' has no attribute 'truncated_normal'

继续升级吧,如果你是用了tensorflow2.0的话,那你应该用keras==2.3啦~~,因为keras在这一步会调用你的tensorflow。你也可以考虑降级。


问题3:

  File "/home/ailab/anaconda3/envs/tf/lib/python3.6/site-packages/tensorflow_core/python/eager/execute.py", line 67, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.InvalidArgumentError: 2 root error(s) found.
  (0) Invalid argument:   Expected image (JPEG, PNG, or GIF), got unknown format starting with '\000\000\000\001Bud1\000E@\000\000\000 \000'
	 [[{{node DecodeJpeg}}]]
	 [[IteratorGetNext]]
  (1) Invalid argument:   Expected image (JPEG, PNG, or GIF), got unknown format starting with '\000\000\000\001Bud1\000E@\000\000\000 \000'
	 [[{{node DecodeJpeg}}]]
	 [[IteratorGetNext]]
	 [[IteratorGetNext/_8]]
0 successful operations.
0 derived errors ignored. [Op:__inference_distributed_function_39947]

解决方法:这个是因为你的数据文件夹中有其他非图片的文件夹,因为你是用了特别的读取方式,会把全部文件都读取,所以你要在读取前判断他是不是图片就可以了。比如我下面这样:

修改前
    train_covers_filename = tf.constant([train_covers_dir + filename for filename in os.listdir(train_covers_dir) ])
    train_nocovers_filename = tf.constant([train_nocovers_dir + filename for filename in os.listdir(train_nocovers_dir) ])
修改后
    train_covers_filename = tf.constant([train_covers_dir + filename for filename in os.listdir(train_covers_dir) if filename.endswith('.jpg')])
    train_nocovers_filename = tf.constant([train_nocovers_dir + filename for filename in os.listdir(train_nocovers_dir) if filename.endswith('.jpg')])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!