PRBonn / bonnetal

Bonnet and then some! Deep Learning Framework for various Image Recognition Tasks. Photogrammetry and Robotics Lab, University of Bonn
MIT License
234 stars 60 forks source link

Semantic Segmentation: Only 2 of 3 classes get trained #27

Closed ohad-denh closed 4 years ago

ohad-denh commented 4 years ago

Hey there,

I am trying to train different backbone/decoder combinations in a semantic segmentation task. My data is similar to the sugarbeets from the old bonnet, with 3 classes: background, carrot, and weed.

Somehow I always end up training only the first two classes. From how I understand it, the number of classes is defined completely in the cfg-file, right? With labels, label-weights and color_map. I would appreciate any help :)

I just double-checked before posting, and noticed that when I run the calculate_segmentation_weights, I dont get differences in frequencies in the carrot and weed classes, which is of course weird but I cant see the reason.

Edit: To be exact, both are Zero. Num of pixels: 681984000 Frequency: [0.89665005 0. 0. ] I cant seem to know why

I'll attach the cfg I'm using right now. Best regards, Olli

P.S. Any chance you got pretrained models for the sugarbeet data in this framework?

backbone:
  OS: 8
  bn_d: 0.001
  dropout: 0.0
  extra:
    shallow_feats: true
    width_mult: 1.0
  name: mobilenetv2
  train: true
dataset:
  color_map:
    0:
    - 0
    - 0
    - 0
    1:
    - 255
    - 0
    - 0
    2:
    - 0
    - 0
    - 255
  img_means:
  - 0.42437694635119927
  - 0.5040352731582203
  - 0.4624443929799188
  img_prop:
    depth: 3
    height: 720
    width: 1280
  img_stds:
  - 0.14995696217848253
  - 0.1564923538805844
  - 0.17123649653037434
  labels:
    0: ground
    1: carrot
    2: weed
  labels_w:
    0: 0.10334995
    1: 1.0
    2: 1.0
  location: dataset/leaf1280/
  name: leaf1280
  workers: 12
decoder:
  bn_d: 0.001
  dropout: 0.0
  extra:
    aspp_channels: 64
    last_channels: 32
    skip_os:
    - 4
    - 2
  name: aspp_residual_attention
  train: true
head:
  dropout: 0.0
  name: segmentation
train:
  avg_N: 3
  batch_size: 3
  crop_prop:
    height: 448
    width: 448
  down_epochs: 0
  final_decay: 0.99
  loss: xentropy
  max_epochs: 1000
  max_lr: 0.001
  max_momentum: 0.9
  min_lr: 0.001
  min_momentum: 0.9
  report_batch: 1
  report_epoch: 1
  save_imgs: false
  save_summary: false
  up_epochs: 0
  w_decay: 1.0e-05
tano297 commented 4 years ago

Hi,

It looks like your cfg file is proper, but if you have a large class imbalance of background and carrot overwhelmingly large in contrast to weeds, then it makes sense that the weed class doesn't show up in the results. You can try with a higher weight for that class.

ohad-denh commented 4 years ago

Thanks for having a look! I tried that already, but also I noticed my data was a little bit "flawed", with really heavy imbalance, as you suggested. Right now I'm waiting for new data, so I guess I'll just close this and hope it works soon ;)

For my other question, you didn't train any bonnetal-net with your sugarbeet-data? If you did, I would be very happy to hear

tano297 commented 4 years ago

Unfortunately, I don't think I have a model for the sugarbeet data on this framework :/ sorry