Open athulvingt opened 2 years ago
/content/drive/MyDrive/Nature
step-1 !pip3 install tensorflow==2.4.1
step-2 !pip3 install tensorflow--gpu !pip3 install imgaug !pip install pixellib==0.5.2 !pip install labelme2coco==0.1.2 !pip install Pillow==9.0.0
step-3 !pip install imgaug !pip install pixellib --upgrade
dataset !wget "https://github.com/ayoolaolafenwa/PixelLib/releases/download/1.0.0/Nature.zip"
pretrainedweights
correcting the dataset-code
import json import os from tqdm import tqdm
DATA_DIR = r"/content/drive/MyDrive/Nature/Nature" for _dir in os.listdir(f"{DATA_DIR}"): DATA_SET = f"{DATA_DIR}/{_dir}" for file in tqdm(os.listdir(DATA_SET)): if file.endswith(".json"): with open(os.path.join(DATA_SET, file), 'r') as f: data = json.load(f) data['imagePath'] = data['imagePath'].replace( '..\', '').replace("images\", "") with open(os.path.join(DATA_SET, file), 'w') as f: json.dump(data, f)
visualize::step5
import pixellib from pixellib.custom_train import instance_custom_training
vis_img = instance_custom_training() vis_img.load_dataset("Nature") vis_img.visualize_sample()
step:6 train:
import pixellib from pixellib.custom_train import instance_custom_training
vis_img = instance_custom_training() vis_img.load_dataset("Nature") vis_img.visualize_sample()
new training started at 12:18 12082022
eval
import pixellib from pixellib.custom_train import instance_custom_training
train_maskrcnn = instance_custom_training() train_maskrcnn.modelConfig(network_backbone = "resnet101", num_classes= 2) train_maskrcnn.load_dataset("Nature") train_maskrcnn.evaluate_model(r"/content/drive/MyDrive/Nature/mask_rcnn_models/mask_rcnn_model.001-0.938751.h5")
import pixellib from pixellib.instance import custom_segmentation import cv2
segment_image = custom_segmentation() segment_image.inferConfig(num_classes= 2, class_names= ["BG", "butterfly", "squirrel"]) segment_image.load_model(r"/content/drive/MyDrive/Nature/mask_rcnn_model_249.h5") segmask, output = segment_image.segmentImage(r"/content/drive/MyDrive/Nature/Nature/test/butterfly (12).jpg", show_bboxes= True) cv2.imwrite("butterfly (12).jpg", output) print(output.shape)
I trained a MaskRCNN model using Resent50 backbone on Nature dataset (butterfly and squirrel, 2 class dataset). After training for 300 , batch size 2 epochs this is the result I got
.I am not getting the results as mentioned in the blog article https://towardsdatascience.com/custom-instance-segmentation-training-with-7-lines-of-code-ff340851e99b. I am not sure if I am doing something wrong
One other thing I noticed that every time I load the same model and inference on same image, I get different results