-1

我将Mask_RCNN 模块与烧瓶一起使用

当我不添加时K.clear_session(),我在训练和预测模块中面临这个错误

错误无法将 feed_dict 键解释为张量:张量张量(\"Placeholder:0\", shape=(7, 7, 3, 64), dtype=float32) is not an element of this graph."}

Weights:  coco
Dataset:  ./files/coco/dataset
Logs:  ./files/coco/log1/
..........................config.........................

Configurations:
BACKBONE                       resnet101
BACKBONE_STRIDES               [4, 8, 16, 32, 64]
BATCH_SIZE                     1
BBOX_STD_DEV                   [0.1 0.1 0.2 0.2]
DETECTION_MAX_INSTANCES        100
DETECTION_MIN_CONFIDENCE       0.744
DETECTION_NMS_THRESHOLD        0.3
GPU_COUNT                      1
GRADIENT_CLIP_NORM             5.0
IMAGES_PER_GPU                 1
IMAGE_MAX_DIM                  1024
IMAGE_META_SIZE                24
IMAGE_MIN_DIM                  800
IMAGE_MIN_SCALE                0
IMAGE_RESIZE_MODE              square
IMAGE_SHAPE                    [1024 1024    3]
LEARNING_MOMENTUM              0.9
LEARNING_RATE                  0.001
LOSS_WEIGHTS                   {'rpn_class_loss': 1.0, 'rpn_bbox_loss': 1.0, 'mrcnn_class_loss': 1.0, 'mrcnn_bbox_loss': 1.0, 'mrcnn_mask_loss': 1.0}
MASK_POOL_SIZE                 14
MASK_SHAPE                     [28, 28]
MAX_GT_INSTANCES               100
MEAN_PIXEL                     [123.7 116.8 103.9]
MINI_MASK_SHAPE                (56, 56)
NAME                           surgery
NUM_CLASSES                    12
POOL_SIZE                      7
POST_NMS_ROIS_INFERENCE        1000
POST_NMS_ROIS_TRAINING         2000
ROI_POSITIVE_RATIO             0.33
RPN_ANCHOR_RATIOS              [0.5, 1, 2]
RPN_ANCHOR_SCALES              (32, 64, 128, 256, 512)
RPN_ANCHOR_STRIDE              1
RPN_BBOX_STD_DEV               [0.1 0.1 0.2 0.2]
RPN_NMS_THRESHOLD              0.7
RPN_TRAIN_ANCHORS_PER_IMAGE    256
STEPS_PER_EPOCH                100
TRAIN_BN                       False
TRAIN_ROIS_PER_IMAGE           200
USE_MINI_MASK                  True
USE_RPN_ROIS                   True
VALIDATION_STEPS               20
WEIGHT_DECAY                   0.0001


Loading weights  ./routeDefine/coco/mrcnn/mask_rcnn_coco.h5
Exception in thread Thread-4:
Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1092, in _run
    subfeed, allow_tensor=True, allow_operation=False)
  File "/home/ubuntu/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3490, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File "/home/ubuntu/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3569, in _as_graph_element_locked
    raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("Placeholder:0", shape=(7, 7, 3, 64), dtype=float32) is not an element of this graph.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/anaconda3/envs/tf-gpu/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/ubuntu/anaconda3/envs/tf-gpu/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ubuntu/AI_Project6/routeDefine/coco/saveModelmn.py", line 111, in model
    main()
  File "/home/ubuntu/AI_Project6/routeDefine/coco/saveModelmn.py", line 108, in main
    trainmodel()
  File "/home/ubuntu/AI_Project6/routeDefine/coco/savemodel.py", line 342, in trainmodel
    "mrcnn_bbox", "mrcnn_mask"])
  File "/home/ubuntu/AI_Project6/routeDefine/coco/mrcnn/modelsave.py", line 2101, in load_weights
    saving.load_weights_from_hdf5_group_by_name(f, layers)
  File "/home/ubuntu/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/engine/saving.py", line 1022, in load_weights_from_hdf5_group_by_name
    K.batch_set_value(weight_value_tuples)
  File "/home/ubuntu/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 2440, in batch_set_value
    get_session().run(assign_ops, feed_dict=feed_dict)
  File "/home/ubuntu/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run
    run_metadata_ptr)
  File "/home/ubuntu/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1095, in _run
    'Cannot interpret feed_dict key as Tensor: ' + e.args[0])
TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(7, 7, 3, 64), dtype=float32) is not an element of this graph.

如果我运行文件,K.clear_session()那么它会停止当前的工作模块并启动我想要运行的模块,就像预测模块正在运行一样,然后我点击训练模块它会停止预测并运行训练。

请帮我

4

1 回答 1

0

似乎您正在尝试在不同的会话中进行训练和预测

由于您尚未共享源代码,因此我可以建议您以下

  1. 为训练和预测创建不同的占位符
  2. sess设为全局变量,这样对于 Flask GET/POST 装饰器函数,您将共享相同的会话对象
于 2019-06-19T08:23:46.263 回答