Reputation: 11
This is my code
import os
import cv2
from mrcnn.config import Config # Import the Config class
from mrcnn import model as modellib
from mrcnn import utils
# Define configuration parameters
class MyConfig(Config):
NAME = "my_config"
IMAGES_PER_GPU = 1
DETECTION_MIN_CONFIDENCE = 0.9
IMAGE_MAX_DIM = 1024 # Adjust this value based on your requirements
# Rest of your code...
# Load the dataset
dataset_dir = "output/histogram_equalization"
image_subdirs = os.listdir(dataset_dir)
# Create a list of image paths and corresponding class IDs
image_paths = []
class_ids = []
for image_subdir in image_subdirs:
image_dir = os.path.join(dataset_dir, image_subdir)
for image_filename in os.listdir(image_dir):
image_path = os.path.join(image_dir, image_filename)
image_paths.append(image_path)
class_ids.append(int(image_subdir))
# Load and preprocess images
images = []
for image_path in image_paths:
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (MyConfig.IMAGE_MAX_DIM, MyConfig.IMAGE_MAX_DIM))
images.append(image)
# Generate bounding boxes and masks
bboxes = []
masks = []
for image_id in range(len(images)):
class_id = class_ids[image_id]
bbox = utils.generate_bbox(images[image_id], class_id)
masks.append(utils.generate_mask_for_bbox(images[image_id], bbox))
bboxes.append(bbox)
# Convert data into a format suitable for Mask R-CNN training
dataset = {
"images": images,
"class_ids": class_ids,
"bboxes": bboxes,
"masks": masks
}
# Train the Mask R-CNN model
model = modellib.MaskRCNN(config=MyConfig(), model_dir="./")
# model.load_weights("mask_rcnn_weights.h5", by_name=True) # Load pre-trained weights if available
model.train(dataset, dataset, epochs=20, layers="all") # Adjust layers based on your needs
# Save the trained model
model.keras_model.save("mask_rcnn_model.h5")
I install tensorflow and keras and all dependencce but all time show
C:\Users\mhlim\OneDrive\Desktop\Image_processing\venv\Scripts\python.exe C:\Users\mhlim\OneDrive\Desktop\Image_processing\RCNN.py
Traceback (most recent call last):
File "C:\Users\mhlim\OneDrive\Desktop\Image_processing\RCNN.py", line 4, in <module>
from mrcnn import model as modellib
File "C:\Users\mhlim\OneDrive\Desktop\Image_processing\venv\Lib\site-packages\mrcnn\model.py", line 24, in <module>
import keras.engine as KE
ModuleNotFoundError: No module named 'keras.engine'
Upvotes: 1
Views: 4533
Reputation: 84
Make sure your environment is python 3+ version.
uninstall the packages and freshly install using pip, also update pip version.
pip install --upgrade pip
pip install --upgrade setuptools
pip install --upgrade tensorflow keras mrcnn
try the following too
!pip uninstall keras-nightly
!pip uninstall -y tensorflow
!pip install h5py==2.10.0
!pip install tensorflow==1.15
!pip install tensorflow-gpu==1.15.0
!pip install keras==2.1.6
Upvotes: 2