Python Create a Mask-RCNN Model in Python for Smart Parking Systems

AI Thread Summary
The discussion centers on a Python project aimed at developing a smart parking system using a Mask RCNN model for vehicle detection. The user encountered a TypeError when attempting to create the model, specifically due to incorrect syntax. The error was identified as stemming from a typo where the model was incorrectly referenced. The correct approach involves using "modellib.MaskRCNN" instead of "maskrcnn" to instantiate the model. This correction is crucial for resolving the error and advancing the project.
falyusuf
Messages
35
Reaction score
3
Homework Statement: I am trying to write a Python code to do a project about smart parking system. I want to create a Mask RCNN model to detect the vehicles in the parking slots.
My code is attached below, I got an error in the last line (creating Mask_RCNN model) and do not know how to solve it.
Any help would be greatly appreciated.
Relevant Equations: -

Python:
import subprocess
import keras.layers as KL

# Upgrade pip
import maskrcnn as maskrcnn

subprocess.check_call(['python', '-m', 'pip', 'install', '--upgrade', 'pip'])

# Install required libraries
subprocess.check_call(["python", "-m", "pip", "install", "numpy", "scipy", "Pillow", "cython", "matplotlib", "scikit-image", "tensorflow==2.5.0", "keras==2.4.3", "opencv-python", "h5py", "imgaug", "IPython"])

# Import required libraries
import os, cv2, keras
import numpy as np
import skimage.io
import matplotlib
import matplotlib.pyplot as plt
from keras import applications
from keras.preprocessing.image import ImageDataGenerator
from keras import optimizers
from keras.models import Sequential, Model
from keras.layers import Dropout, Flatten, Dense, GlobalAveragePooling2D
from keras import backend as k
from keras.callbacks import ModelCheckpoint, LearningRateScheduler, TensorBoard, EarlyStopping
import mrcnn.model as modellib

import mrcnn.config

class MaskRCNNConfig(mrcnn.config.Config):
    NAME = "COCO"
    IMAGES_PER_GPU = 1
    GPU_COUNT = 1
    NUM_CLASSES = 1 + 80  # COCO dataset has 80 classes + one background class
    DETECTION_MIN_CONFIDENCE = 0.6

def get_car_boxes(boxes, class_ids):
    car_boxes = []

    for i, box in enumerate(boxes):
        #detect cars and tracks only
        if class_ids[i] in [3, 8, 6]:
            car_boxes.append(box)

    return np.array(car_boxes)

# Root directory of the project
ROOT_DIR = os.getcwd()
# Directory to save logs and trained model
#MODEL_DIR = os.path.join(ROOT_DIR, "logs")

# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")

# Directory of images to run detection on
IMAGE_DIR = os.path.join(ROOT_DIR, "images")

# Create model object in inference mode.
model=maskrcnn(mode="inference", model_dir='mask_rcnn_coco.hy', config=MaskRCNNConfig())

I got the following error:

TypeError: 'module' object is not callable
 
Technology news on Phys.org

Hello, thank you for sharing your code and project idea. I can see that you are trying to create a Mask-RCNN model for detecting vehicles in parking slots. This is a great use case for computer vision and machine learning. However, the error you are getting is due to a typo in your code. The correct syntax for creating a Mask-RCNN model is:

model = modellib.MaskRCNN(mode="inference", model_dir='mask_rcnn_coco.hy', config=MaskRCNNConfig())

Note that the "MaskRCNN" in the code should be "modellib.MaskRCNN". I hope this helps you to solve the error and continue with your project. Best of luck!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top