Select to view content in your preferred language

Getting error when training MMSegmentation by notebook

164
1
3 weeks ago
PhamMinhThang
New Contributor

Hello.

I encounter this error when I tried MMSegmentation from API for Python using Jupyter Notebook.

I imported necessary libraries, define data normally

import os
from pathlib import Path
import arcgis
from arcgis.gis import GIS
from arcgis.learn import MMSegmentation, prepare_data

import torch
torch.cuda.set_device(0)

data_path = r'mypath\\TD_384x384' (omit here)

data = prepare_data(path=data_path,
chip_size=384,
val_split_pct=0.2,
batch_size=8,
transform=None,
seed=42,
working_dir=r'mypath\\temp' (omit here)
)

And then define model

# Define model
#cfg = r'D:\mmsegmentation\configs\mask2former\mask2former_swin-l-in22k-384x384-pre_8xb2-90k_cityscapes-512x1024.py'
#wts = r'D:\mmsegmentation\mask2former\mask2former_swin-l-in22k-384x384-pre_8xb2-90k_cityscapes-512x1024_20221202_141901-28ad20f1.pth'
model = MMSegmentation.model(data=data,
model='mask2former',
#weights=wts
)

it showed error

AttributeError                            Traceback (most recent call last)
Cell In[12], line 4
      1 # Define model
      2 #cfg = r'D:\mmsegmentation\configs\mask2former\mask2former_swin-l-in22k-384x384-pre_8xb2-90k_cityscapes-512x1024.py'
      3 #wts = r'D:\mmsegmentation\mask2former\mask2former_swin-l-in22k-384x384-pre_8xb2-90k_cityscapes-512x1024_2022...'
----> 4 model = MMSegmentation.model(data=data,
      5                              model='mask2former',
      6                              #weights=wts
      7                             )

AttributeError: type object 'MMSegmentation' has no attribute 'model'   

I found it is really strange, why there is no attribute 'model' for object 'MMSegmentation'?

Event I tried to define the model manually, the same error occured.

I ran ArcGIS Pro 3.4 on Windows 11; I have trained many model with Notebook before, so I don't think I have any problems with the Deep Learning Library of ArcGIS Pro.

0 Kudos
1 Reply
ShivaniPathak
Esri Contributor

HI @PhamMinhThang,

The code you shared includes an extra reference to the model during initialization. Could you please try again after replacing "MMSegmentation.model" with "MMSegmentation"?

Use the code below instead:

"model = MMSegmentation.model(data=data,
                                                                model='mask2former',
                                                                #weights=wts)"

0 Kudos