0

AttributeError: module 'tensorflow' has no attribute 'placeholder'

config = CustomConfig()
model = modellib.MaskRCNN (mode= "training", config=config, model_dir=DEFAULT_LOGS_DIR)
weights_path = COCO_WEIGHTS_PATH # Download weights file
if not os.path.exists(weights_path):
  utils.download_trained_weights(weights_path)
model.load_weights(weights_path, by_name=True, exclude=["mrcnn_class_logits", 
                                                        "mrcnn_bbox_fc","mrcnn_bbox", 
                                                        "mrcnn_mask"])

Can anyone please tell me how to fix this attribute error.

I am using

!pip install keras==2.2.5
%tensorflow_version 2.x
Magic
  • 1
  • You could get errors due to some files of the *python packages* conflicting with `tensorflow` and `keras`, so I recommend you to carefully follow the [installation](https://github.com/matterport/Mask_RCNN#installation) steps ([using the most recent versions](https://github.com/keras-team/keras/releases/tag/2.4.0)) and try again with clean files. – user11717481 Dec 28 '22 at 02:14
  • [please do not post images as code/data/errors](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors) – user11717481 Dec 28 '22 at 03:31

2 Answers2

0

It is possible that the error is generated by the configuration that you use as a parameter config in MaskRCNN, which has some slight differences depending on the stages (test, training), you can find more information in coco.py

from mrcnn.config import Config
#...

class CocoConfig(Config): 
    NAME = "coco" 
    IMAGES_PER_GPU = 2 
    NUM_CLASSES = 1 + 80 

# ...
config = CocoConfig()
model = modellib.MaskRCNN(mode="training", config=config, model_dir=DEFAULT_LOGS_DIR)
weights_path = COCO_WEIGHTS_PATH
if not os.path.exists(weights_path):
    utils.download_trained_weights(weights_path)
model.load_weights(weights_path, by_name=True, exclude=["mrcnn_class_logits", 
                                                        "mrcnn_bbox_fc",
                                                        "mrcnn_bbox", 
                                                        "mrcnn_mask"]) 

no train

class InferenceConfig(CocoConfig): 
    GPU_COUNT = 1
    IMAGES_PER_GPU = 1
    DETECTION_MIN_CONFIDENCE = 0 
user11717481
  • 1
  • 9
  • 15
  • 25
0

This might be the issue regarding python version and tensorflow version. I have tried mask rcnn on 3.8 python version but it didnt worked. for me below setup worked.

on python 3.6.0:

tensorflow==1.14.0
Keras==2.1.3
pycocotools==2.0.4
numpy==1.16.4
matplotlib==2.2.5
Mogli141
  • 65
  • 6