priya-dwivedi / Deep-Learning

MIT License
3.35k stars 2.49k forks source link

mask_rcnn_damage_0010.h5 #45

Open vajpaye opened 5 years ago

vajpaye commented 5 years ago

Hi @priya-dwivedi

can you please tell me where can i download this "mask_rcnn_damage_0010.h5" file

soufianesabiri commented 5 years ago

I have same problem please help

vajpaye commented 5 years ago

Hi @soufianesabiri

may I know in what context you are trying to apply this?

vajpaye commented 5 years ago

if we are trying to apply this for car damage detection or in any context follow these steps please: 1.Use the mask_rcnn_coo.h5 https://github.com/matterport/Mask_RCNN/releases 2.train the model with mask_rcnn_coo.h5 3.after training you can save your file to your directory. model_path = os.path.join(ROOT_DIR, "mask_rcnn_damage_0010.h5") model.keras_model.save_weights(model_path)

soufianesabiri commented 5 years ago

thanks for your answer, how to train the model please?? I have installed tensorflow and keras.

vajpaye commented 5 years ago

import os import sys import itertools import math import logging import json import re import random from collections import OrderedDict import numpy as np import matplotlib import matplotlib.pyplot as plt import matplotlib.patches as patches import matplotlib.lines as lines from matplotlib.patches import Polygon from keras.optimizers import SGD, Adam, RMSprop

Root directory of the project

ROOT_DIR = ROOT_DIR = os.path.abspath("../../")

Import Mask RCNN

sys.path.append(ROOT_DIR) # To find local version of the library print(ROOT_DIR) from mrcnn import utils from mrcnn import visualize from mrcnn.visualize import display_images import mrcnn.model as modellib from mrcnn.model import log MODEL_DIR = os.path.join(ROOT_DIR, "logs") print(MODEL_DIR) import car_damage

%matplotlib inline COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5") print(COCO_MODEL_PATH)

Download COCO trained weights from Releases if needed

if not os.path.exists(COCO_MODEL_PATH): utils.download_trained_weights(COCO_MODEL_PATH)

BATCH_SIZE = 128 NB_EPOCH = 2 NB_CLASSES = 1 VERBOSE = 1 VALIDATION_SPLIT = 0.2 OPTIM = RMSprop()

config = car_damage.damageConfig() CUSTOM_DIR = os.path.join(ROOT_DIR, "customImages") print(CUSTOM_DIR)

class InferenceConfig(config.class):

Run detection on one image at a time

GPU_COUNT = 1
IMAGES_PER_GPU = 1

config = InferenceConfig() config.display()

def get_ax(rows=1, cols=1, size=16): """Return a Matplotlib Axes array to be used in all visualizations in the notebook. Provide a central point to control graph sizes.

Adjust the size attribute to control how big to render images
"""
_, ax = plt.subplots(rows, cols, figsize=(size*cols, size*rows))
return ax

Load dataset

Get the dataset from the releases page

https://github.com/matterport/Mask_RCNN/releases

dataset_train = car_damage.damageDataset() print(CUSTOM_DIR) dataset_train.load_damage(CUSTOM_DIR, "train")

Must call before using the dataset

dataset_train.prepare()

print("Image Count: {}".format(len(dataset_train.image_ids))) print("Class Count: {}".format(dataset_train.num_classes)) for i, info in enumerate(dataset_train.class_info): print("{:3}. {:50}".format(i, info['name']))

Load dataset

Get the dataset from the releases page

https://github.com/matterport/Mask_RCNN/releases

dataset_val = car_damage.damageDataset() dataset_val.load_damage(CUSTOM_DIR, "val")

Must call before using the dataset

dataset_val.prepare()

print("Image Count: {}".format(len(dataset_val.image_ids))) print("Class Count: {}".format(dataset_val.num_classes)) for i, info in enumerate(dataset_val.class_info): print("{:3}. {:50}".format(i, info['name']))

image_ids = np.random.choice(dataset_train.image_ids, 4) for image_id in image_ids: image = dataset_train.load_image(image_id) mask, class_ids = dataset_train.load_mask(image_id) visualize.display_top_masks(image, mask, class_ids, dataset_train.class_names) print(image_id) print(dataset_train.source_class_ids)

print(image_path)

print(dataset_train.image_info[image_id]["source"])
print(dataset_train.source_class_ids[dataset_train.image_info[image_id]["source"]])

print(MODEL_DIR)

model = modellib.MaskRCNN(mode="training", config=config, model_dir=MODEL_DIR)

init_with = "coco" # imagenet, coco, or last

if init_with == "imagenet": model.load_weights(model.get_imagenet_weights(), by_name=True) elif init_with == "coco":

Load weights trained on MS COCO, but skip layers that

# are different due to the different number of classes
# See README for instructions to download the COCO weights
model.load_weights(COCO_MODEL_PATH, by_name=True,
                   exclude=["mrcnn_class_logits", "mrcnn_bbox_fc", 
                            "mrcnn_bbox", "mrcnn_mask"])

elif init_with == "last":

Load the last model you trained and continue training

model.load_weights(model.find_last(), by_name=True)

Train the head branches

Passing layers="heads" freezes all layers except the head

layers. You can also pass a regular expression to select

which layers to train by name pattern.

model.train(dataset_train, dataset_val, learning_rate=config.LEARNING_RATE, epochs=1, layers='heads')

model_path = os.path.join(ROOT_DIR, "mask_rcnn_damage.h5") model.keras_model.save_weights(model_path)

soufianesabiri commented 5 years ago

Thanks a lot! I will try this right after.

vajpaye commented 5 years ago

even you can refer this link

https://github.com/matterport/Mask_RCNN/blob/master/samples/demo.ipynb

soufianesabiri commented 5 years ago

thanks!

girijesh18 commented 5 years ago

Hey @vajpaye In Import Mask RCNN import car_damage is giving error that No module named 'car_damage' can you please help to figure it out. Thanks

angyee commented 5 years ago

ValueError: Layer #389 (named "mrcnn_bbox_fc"), weight <tf.Variable 'mrcnn_bbox_fc/kernel:0' shape=(1024, 8) dtype=float32_ref> has shape (1024, 8), but the saved weight has shape (1024, 324)

@vajpaye

girijesh18 commented 5 years ago

@angyee you need to ADD few lines to else condition

print("Loading weights ", weights_path) if args.weights.lower() == "coco":

Exclude the last layers because they require a matching

# number of classes
model.load_weights(weights_path, by_name=True, exclude=[
    "mrcnn_class_logits", "mrcnn_bbox_fc",
"mrcnn_bbox", "mrcnn_mask"])

else: model.load_weights(weights_path, by_name=True, exclude=[ "mrcnn_class_logits", "mrcnn_bbox_fc", "mrcnn_bbox", "mrcnn_mask"])

angyee commented 5 years ago

done exactly same but the result is saving in png image file but no masked image result for a damaged part on the car

splash_20190531T105807

@girijesh18

girijesh18 commented 5 years ago

@angyee I am facing the same issue. Currently, I am working on it and will let you know if I would resolve it. Please let me know if you get some lead in this

girijesh18 commented 5 years ago

@angyee I am able to run the algorithm successfully but still, the trained weights are not able to generate a splash. I think it needs more data and a higher number of epochs to generate the splash. Let me know if you are facing any issues to run this algorithm.

ritikgarg655 commented 4 years ago

import os import sys import itertools import math import logging import json import re import random from collections import OrderedDict import numpy as np import matplotlib import matplotlib.pyplot as plt import matplotlib.patches as patches import matplotlib.lines as lines from matplotlib.patches import Polygon from keras.optimizers import SGD, Adam, RMSprop

Root directory of the project

ROOT_DIR = ROOT_DIR = os.path.abspath("../../")

Import Mask RCNN

sys.path.append(ROOT_DIR) # To find local version of the library print(ROOT_DIR) from mrcnn import utils from mrcnn import visualize from mrcnn.visualize import display_images import mrcnn.model as modellib from mrcnn.model import log MODEL_DIR = os.path.join(ROOT_DIR, "logs") print(MODEL_DIR) import car_damage

%matplotlib inline COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5") print(COCO_MODEL_PATH)

Download COCO trained weights from Releases if needed

if not os.path.exists(COCO_MODEL_PATH): utils.download_trained_weights(COCO_MODEL_PATH)

BATCH_SIZE = 128 NB_EPOCH = 2 NB_CLASSES = 1 VERBOSE = 1 VALIDATION_SPLIT = 0.2 OPTIM = RMSprop()

config = car_damage.damageConfig() CUSTOM_DIR = os.path.join(ROOT_DIR, "customImages") print(CUSTOM_DIR)

class InferenceConfig(config.class):

Run detection on one image at a time

GPU_COUNT = 1 IMAGES_PER_GPU = 1

config = InferenceConfig() config.display()

def get_ax(rows=1, cols=1, size=16): """Return a Matplotlib Axes array to be used in all visualizations in the notebook. Provide a central point to control graph sizes.

Adjust the size attribute to control how big to render images
"""
_, ax = plt.subplots(rows, cols, figsize=(size*cols, size*rows))
return ax

Load dataset

Get the dataset from the releases page

https://github.com/matterport/Mask_RCNN/releases

dataset_train = car_damage.damageDataset() print(CUSTOM_DIR) dataset_train.load_damage(CUSTOM_DIR, "train")

Must call before using the dataset

dataset_train.prepare()

print("Image Count: {}".format(len(dataset_train.image_ids))) print("Class Count: {}".format(dataset_train.num_classes)) for i, info in enumerate(dataset_train.class_info): print("{:3}. {:50}".format(i, info['name']))

Load dataset

Get the dataset from the releases page

https://github.com/matterport/Mask_RCNN/releases

dataset_val = car_damage.damageDataset() dataset_val.load_damage(CUSTOM_DIR, "val")

Must call before using the dataset

dataset_val.prepare()

print("Image Count: {}".format(len(dataset_val.image_ids))) print("Class Count: {}".format(dataset_val.num_classes)) for i, info in enumerate(dataset_val.class_info): print("{:3}. {:50}".format(i, info['name']))

image_ids = np.random.choice(dataset_train.image_ids, 4) for image_id in image_ids: image = dataset_train.load_image(image_id) mask, class_ids = dataset_train.load_mask(image_id) visualize.display_top_masks(image, mask, class_ids, dataset_train.class_names) print(image_id) print(dataset_train.source_class_ids)

print(image_path)

print(dataset_train.image_info[image_id]["source"]) print(dataset_train.source_class_ids[dataset_train.image_info[image_id]["source"]])

print(MODEL_DIR)

model = modellib.MaskRCNN(mode="training", config=config, model_dir=MODEL_DIR)

init_with = "coco" # imagenet, coco, or last

if init_with == "imagenet": model.load_weights(model.get_imagenet_weights(), by_name=True) elif init_with == "coco":

Load weights trained on MS COCO, but skip layers that

are different due to the different number of classes

See README for instructions to download the COCO weights

model.load_weights(COCO_MODEL_PATH, by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc", "mrcnn_bbox", "mrcnn_mask"]) elif init_with == "last":

Load the last model you trained and continue training

model.load_weights(model.find_last(), by_name=True)

Train the head branches

Passing layers="heads" freezes all layers except the head

layers. You can also pass a regular expression to select

which layers to train by name pattern.

model.train(dataset_train, dataset_val, learning_rate=config.LEARNING_RATE, epochs=1, layers='heads')

model_path = os.path.join(ROOT_DIR, "mask_rcnn_damage.h5") model.keras_model.save_weights(model_path)

@vajpaye I am facing error in save_weights: TypeError: can't pickle _thread.RLock objects mrcnn

achieverprince commented 4 years ago

Same here, result image is same as input. This never works