TypeError: 'NoneType' object is not subscriptable

I followed tutorial_cxr for training classification model. But, but I’m failing at running tlt-train command.

2019-05-22 02:08:14.053192: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 9944 MB memory) -> physical GPU (device: 1, name: GeForce RTX 2080 Ti, pci bus id: 0000:03:00.0, compute capability: 7.5)
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "common/scripts/train.py", line 25, in <module>
  File "common/scripts/train.py", line 20, in main
  File "classification/scripts/train_classification.py", line 210, in train_classification
TypeError: 'NoneType' object is not subscriptable

Thanks in advance.

Faced the same issue when I ran tutorial_brats.

Traceback (most recent call last):=========]  train_loss: 0.9822  train_dice_et: 0.0073  train_dice_tc: 0.0178  train_dice_wt: 0.0063  train_dice: 0.0105  time: 32.52s        
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "common/scripts/train.py", line 25, in <module>
  File "common/scripts/train.py", line 18, in main
  File "segmentation/scripts/train_segmentation.py", line 316, in train_segmentation
  File "common/trainers/fitter.py", line 500, in standard_fit
  File "common/metrics/val_classes.py", line 165, in get
TypeError: object of type 'NoneType' has no len()

Hi, thank you for your interest in the training SDK.

This type of error can happen if there is something wrong with the labels in your dataset. For example, it happens if all labels only contain zeros.

@hroth3hm8y, thanks for the reply.
I am using BRATS-2018 Dataset as mentioned in the example for Segmentation model.
For testing purposes I used only 3 images.

What happens if you use more than 3 images?

Hi, I tried with more than 3 images and faced same error.
I am attaching Datalist.json and Train config file. Can you please correct me if I am wrong anywhere.

Datalist.json

{
	"label_format": [1,1,1,1,1,1,1,1,1,1,1,1,1,1],
	"training":
	[	
		{
			"image" : "images/00000003_003.png",
			"label" : [0,0,0,1,0,0,0,0,0,0,0,0,0,1]
		},
		{
			"image" : "images/00000001_000.png",
			"label" : [0,1,0,0,0,0,0,0,0,0,0,0,0,0]
		},
		{
			"image" : "images/00000001_001.png",
			"label" : [0,1,0,0,0,0,0,0,0,0,1,0,0,0]
		},
		{
			"image" : "images/00000002_000.png",
			"label" : [0,0,0,0,0,0,0,0,0,0,0,0,0,0]
		},
		{
			"image" : "images/00000003_000.png",
			"label" : [0,0,0,0,0,0,0,0,0,0,0,0,0,1]
		},
		{
			"image" : "images/00000001_002.png",
			"label" : [0,1,1,0,0,0,0,0,0,0,0,0,0,0]
		}
	],
	"validation":
	[
		{
			"image" : "images/00000003_001.png",
			"label" : [0,0,0,0,0,0,0,0,0,0,0,0,0,1]
		},
		{
			"image" : "images/00000003_002.png",
			"label" : [0,0,0,0,0,0,0,0,0,0,0,0,0,1]
		}
	]
}

Train_config

{
    
    "image_base_dir": "/var/tmp/models/classification_chestxray/ChestX-ray14",
    "weight_decay": 1e-5,
    "batch_size": 20,
    "epochs": 40,
    "multi_gpu": false,
    "num_workers": 8,
    "network_input_size": [256, 256],
    "data_format": "channels_last",

    "train":
    {
        "loss":
        {
            "name": "losses.classification_loss"
        },
        "optimizer":
        {
            "name": "Adam",
            "lr": 2e-4
        },
        "pre_transforms":
        [
            {
                "name": "transforms.LoadPng",
                "fields": ["image"]
            },
            {
                "name": "transforms.CropRandomSubImageInRange",
                "lower_size": [0.9,0.9],
                "data_format": "grayscale",
                "image_field": "image",
                "max_displacement": 200
            },
            {
                "name": "transforms.NPResizeImage",
                "applied_keys": ["image"],
                "output_shape": [256,256],
                "data_format": "grayscale"
            },
            {
                "name": "transforms.NP2DRotate",
                "applied_keys": ["image"],
                "angle": 7,
                "random": true,
                "data_format": "grayscale"
            },

            {
                "name": "transforms.NPExpandDims",
                "applied_keys": "image",
                "expand_axis": 2
            },
            {
                "name": "transforms.NPRepChannels",
                "applied_keys": "image",
                "channel_axis": 2,
                "repeat": 3
            },
            {
                "name": "transforms.CenterData",
                "applied_keys": "image",
                "subtrahend": [2876.37, 2876.37,2876.37],
                "divisor": [883, 883, 883]
            }


        ]
    },

    "validate":
    {
        "pre_transforms":
        [
            {
                "name": "transforms.LoadPng",
                "fields": ["image"]
            },
            {
                "name": "transforms.NPResizeImage",
                "applied_keys": ["image"],
                "output_shape": [256,256],
                "data_format": "grayscale"
            },
            {
                "name": "transforms.NPExpandDims",
                "applied_keys": "image",
                "expand_axis": 2
            },
            {
                "name": "transforms.NPRepChannels",
                "applied_keys": "image",
                "channel_axis": 2,
                "repeat": 3
            },
            {
                "name": "transforms.CenterData",
                "applied_keys": "image",
                "subtrahend": [2876.37, 2876.37,2876.37],
                "divisor": [883, 883, 883]
            }


        ],

        "metrics":
        [
            {
                "name": "MetricAverage",
                "tag" : "mean_accuracy",
                "applied_key": "val_accuracy"
            },
            {
                "name": "MetricAUC",
                "tag" : "Average_AUC",
                "applied_key": "binary_preds",
                "label_key": "binary_labels",
                "auc_average": "macro",
                "stopping_metric": true
            },
            {
                "name": "MetricAUC",
                "tag" : "Nodule",
                "class_index": 0,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Mass",
                "class_index": 1,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
                    {
                "name": "MetricAUC",
                "tag" : "Distortion_pulmonary_architecture",
                "class_index": 2,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Pleural_based_mass",
                "class_index": 3,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Granuloma",
                "class_index": 4,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Fluid_in_pleural_space",
                "class_index": 5,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Right_hilar_abnormality",
                "class_index": 6,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Left_hilar_abnormality",
                "class_index": 7,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Major_atelectasis",
                "class_index": 8,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Infiltrate",
                "class_index": 9,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Scarring",
                "class_index": 10,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Pleural_fibrosis",
                "class_index": 11,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Bone_soft_tissue_lesion",
                "class_index": 12,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "Cardiac_abnormality",
                "class_index": 13,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            },
            {
                "name": "MetricAUC",
                "tag" : "COPD",
                "class_index": 14,
                "applied_key": "binary_preds",
                "label_key": "binary_labels"
            }

        ]

    },

    "auxiliary_outputs":
    [
        {
            "name": "common.metrics.metrics.compute_accuracy",
            "tags": "accuracy",
            "use_sigmoid": true
        }
    ]

}

Thank you.

It looks like there is a mismatch between your number of labels (14) and your number of “metrics”. You have 15 (0…14) “MetricAUC” evaluators in your config. Please remove the one with index 14.

Also, your Train_config seems to be missing this section:

"net_config":
{
    "name": "Densenet121",
    "pretrain_weight_name": "/mnt/Models/ChestXrayClassification/densenet121_weights_tf.h5"
},

Note, if you are changing the number of classes to 14, you can not use our pre-trained PLCO model which is trained on 15 classes. Please try training from scratch in this case.

In general, the error means that you attempted to index an object that doesn’t have that functionality. You are trying to subscript an object which you think is a list or dict, but actually is None. NoneType is the type of the None object which represents a lack of value, for example, a function that does not explicitly return a value will return None. ‘NoneType’ object is not subscriptable is the one thrown by python when you use the square bracket notation object[key] where an object doesn’t define the getitem method .

If you want to know above the topics, Visit : typeerror nonetype object is not subscriptable