-1

I used Mask_RCNN module with flask

When I do not add K.clear_session() then I face this error in training and prediction module

error 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."}

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.

If I run file with K.clear_session() then it stops current working module and starts module that I want to run like if prediction module is running then I hit training module it stops prediction and runs training.

please help me

barbsan
  • 3,418
  • 11
  • 21
  • 28
  • Hello Rajan, It would be helpful to everybody if you can format your question so that it is easily readable https://meta.stackexchange.com/questions/22186/how-do-i-format-my-code-blocks – Anant Gupta Jun 19 '19 at 08:18

1 Answers1

0

It seems as if you are trying to do training as well as prediction within different sessions

Since you have not shared the source code, I can suggest you the following

  1. Create different placeholders for training and prediction
  2. Make the sess as a global variable so that for Flask GET/POST decorator functions, you are sharing the same session object
Anant Gupta
  • 1,090
  • 11
  • 11
  • i am using coco pretrained model with keras . please check this link they do not used session variable in code so where i add this ? https://github.com/matterport/Mask_RCNN – RAJAN NAGPAL Jun 19 '19 at 09:03