用 mrcnn 掩盖脑肿瘤

问题描述 投票:0回答:1

我正在尝试在 GitHub 上重新创建这个项目,以使用 MRI 扫描来掩盖脑肿瘤。然而,我在这里遇到了一些问题,因为我改编的代码运行得不太好。一切都很顺利,直到我到达“model.load_weights”部分。它只是表明 NoneType 对象没有属性“lower”。所以我想知道你们能告诉我这里出了什么问题吗?我正在尝试通过 Youtube 视频学习,所以如果我犯了任何错误,请告诉我!多谢!!!另外,如果你们之前已经重新创建了这个项目,如果你们能给我一些建议,那就太好了。

这是我改编的代码。我使用 MakeSense 创建注释文件。

import os
import sys 
import numpy as np 
import pandas as pd 
import skimage 
import matplotlib.pyplot as plt 
import matplotlib.patches 
from numpy import zeros, asarray 
from PIL import Image, ImageDraw import json 
import datetime import cv2

import mrcnn 
from mrcnn.visualize import display_instances 
from mrcnn.utils import extract_bboxes

from mrcnn.utils import Dataset
from matplotlib import pyplot as plt

from mrcnn.config import Config 
from mrcnn.model import MaskRCNN

from mrcnn import model as modellib, utils
df= r"C:\Users\Brain MRI\mask\image_data"
train= os.path.join(df,'train') 
val=os.path.join(df,'val') 
pretrained_model=os.path.join(df,"mask_rcnn_coco.h5") 
log_dir=os.path.join(df,'logs') 
class Configuration(Config): 
  NAME = "coco" GPU_COUNT=1 IMAGES_PER_GPU=1  
  num_classes=1+1 
  STEPS_PER_EPOCH=45
  VALIDATION_STEPS=10
  IMAGE_MAX_DIM=256 
  IMAGE_MIN_DIM=256 
def init(self, num_classes):
  self.NUM_CLASSES = num_classes super().init()
  model_path=pretrained_model 
class BrainScanDataset(utils.Dataset):
def load_brain_scan(self, dataset_dir, subset):
    # Add classes. We have only one class to add.
    self.add_class(
        "tumor", 1, "tumor")

    # Train or validation dataset?
    assert subset in ["train", "val"]
    dataset_dir = os.path.join(df, subset)

    annotations = json.load(open(os.path.join(df, subset, 'annotations_'+subset+'.json')))
    annotations = list(annotations.values())  
    annotations = [a for a in annotations if a['regions']]
   

    # Add images
    for a in annotations:
        if type(a['regions']) is dict:
            polygons = [r['shape_attributes'] for r in a['regions'].values()]
        else:
            polygons = [r['shape_attributes'] for r in a['regions']]

        # load_mask() needs the image size to convert polygons to masks.
        # Unfortunately, VIA doesn't include it in JSON, so we must read
        # the image. This is only managable since the dataset is tiny.
        image_path = os.path.join(df,subset, a['filename'])
        image = skimage.io.imread(image_path)
        height, width = image.shape[:2]

        self.add_image("tumor",
            image_id=a['filename'],  # use file name as a unique image id
            path=image_path,
            width=width, 
            height=height,
            polygons=polygons
        )
def load_mask(self, image_id):
    # If not a farm_cow dataset image, delegate to parent class.
    image_info = self.image_info[image_id]
    if image_info["source"] != "tumor":
        return super(self.__class__, self).load_mask(image_id)
    info = self.image_info[image_id]
    mask = np.zeros([info["height"], info["width"], len(info["polygons"])],
                    dtype=np.uint8)
    for i, p in enumerate(info["polygons"]):
        # Get indexes of pixels inside the polygon and set them to 1
        rr, cc = skimage.draw.polygon(p['all_points_y'], p['all_points_x'])
        mask[rr, cc, i] = 1
def image_reference(self, image_id):
    info = self.image_info[image_id]
    if info["source"] == "tumor":
        return info["path"]
    else:
        super(self.__class__, self).image_reference(image_id)
dataset_train = BrainScanDataset() 
dataset_train.load_brain_scan(df, 'train') 
dataset_train.prepare()

dataset_val = BrainScanDataset() 
dataset_val.load_brain_scan(df, 'val') 
dataset_val.prepare()

model = modellib.MaskRCNN( mode='training', config=Config, model_dir=log_dir )

model.load_weights( pretrained_model, by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc", "mrcnn_bbox", "mrcnn_mask"] )
conv-neural-network mask
1个回答
0
投票

您面临的错误可能是由于预先训练的模型“mask_rcnn_coco.h5”造成的。检查该文件是否正确,并检查路径是否正确。我还建议检查一下

模型.summary() 在 model.load_weights() 之前,它会帮助你判断模型是否正确。

或者您可以检查 load_weights() 是否与 .h5 文件兼容。

© www.soinside.com 2019 - 2024. All rights reserved.