isl-org / Open3D-ML

An extension of Open3D to address 3D Machine Learning tasks
Other
1.88k stars 321 forks source link

[BUG] AttributeError: 'SemanticSegmentation' object has no attribute 'cfg_tb' #241

Closed tvkpz closed 3 years ago

tvkpz commented 3 years ago

This seems to be a bug. I get the following error when I try to train.

Traceback (most recent call last):
  File "open3d_train1.py", line 28, in <module>
    pipeline.run_train()
  File "/home/ubuntu/anaconda3/envs/open3d-ml/lib/python3.7/site-packages/open3d/_ml3d/torch/pipelines/semantic_segmentation.py", line 354, in run_train
    self.save_config(writer)
  File "/home/ubuntu/anaconda3/envs/open3d-ml/lib/python3.7/site-packages/open3d/_ml3d/torch/pipelines/semantic_segmentation.py", line 559, in save_config
    writer.add_text("Description/Open3D-ML", self.cfg_tb['readme'], 0)
AttributeError: 'SemanticSegmentation' object has no attribute 'cfg_tb'

And I cannot find the attribute cfg_tb in the example configurations at least.

charithmu commented 3 years ago

I also encountered the same bug. You can solve it for now by adding this missing variable as in the run_pipeline.py, Example as below. Hope the developers will fix it in upcoming cycles.

pipeline.cfg_tb = {
    "readme": "readme",
    "cmd_line": "cmd_line",
    "dataset": pprint.pformat(cfg_dataset, indent=2),
    "model": pprint.pformat(cfg_model, indent=2),
    "pipeline": pprint.pformat(cfg_pipeline, indent=2),
}
monicavillarreala commented 3 years ago

Hello! I get the same error when trying to run the code, but the solution mentioned by @charithmu didn't solve the problem :( any advice?

hduonggithub commented 3 years ago

@charithmu Can you show where to add your code into run_pipeline.py? I have tried but still get the same error. :(

samux87 commented 3 years ago

@charithmu Can you show where to add your code into run_pipeline.py? I have tried but still get the same error. :(

You can use the run_pipeline.py under Open3D-ML/scripts/ through the train scripts under /Open3D-ML/scripts/train_scripts

hduonggithub commented 3 years ago

Thanks @samux87. I will give it a try.

charithmu commented 3 years ago

Here is a part of a jupyter notebook if someone wants to quickly start experimenting without using the provided scripts. 'cfg_tb' issue may have being fixed or not. I honestly didn't check since few weeks. You will have to modify/extend this code to fit to your custom needs, but that's easy.

Cheers.

import os
import pprint
import time
from pathlib import Path

import numpy as np

# set paths
home_path = str(Path.home())
base_path = home_path + "/dev/Open3D-ML"
dateset_path = home_path + "/datasets/s3dis"
ckpt_base_path = base_path + "/mytests/logs"

# import custom open3d.ml
os.environ["OPEN3D_ML_ROOT"] = base_path
import open3d.ml as _ml3d

# other dataset configs
randlanet_semantickitti_cfg = base_path + "/ml3d/configs/randlanet_semantickitti.yml"
randlanet_s3dis_cfg = base_path + "/ml3d/configs/randlanet_s3dis.yml"

# checkpoints
kpconv_ckpt_path = ckpt_base_path + "/KPFCNN_SmartLab_tf/checkpoint/ckpt-11"
randlanet_ckpt_path = ckpt_base_path + "/RandLANet_SmartLab_tf/checkpoint/ckpt-6"

kwargs = {
    "framework": "tf",
    "device": "cuda",
    "dataset_path": dateset_path,
    "split": "test",
    "ckpt_path": randlanet_ckpt_path,
    "cfg_file": randlanet_s3dis_cfg,
}

# on-the-fly object using kwargs
args = type("args", (object,), kwargs)()
pprint.pprint(kwargs)

# import tensorflow or pytorch
if args.framework == "torch":
    import open3d.ml.torch as ml3d
else:
    import open3d.ml.tf as ml3d
    import tensorflow as tf

gpus = tf.config.experimental.list_physical_devices("GPU")
pprint.pprint(gpus)

# TF GPU settings
if gpus is not None and args.framework == "tf":
    print("Setting up GPUs for TF")
    try:
        for gpu in gpus:
            tf.config.experimental.set_memory_growth(gpu, True)
        if args.device == "cpu":
            tf.config.set_visible_devices([], "GPU")
        elif args.device == "cuda":
            tf.config.set_visible_devices(gpus[0], "GPU")
        else:
            idx = args.device.split(":")[1]
            tf.config.set_visible_devices(gpus[int(idx)], "GPU")
    except RuntimeError as e:
        print(e)

# merge args into config file
def merge_cfg_file(cfg, args, extra_dict):
    if args.device is not None:
        cfg.pipeline.device = args.device
        cfg.model.device = args.device
    if args.split is not None:
        cfg.pipeline.split = args.split
    if args.dataset_path is not None:
        cfg.dataset.dataset_path = args.dataset_path
    if args.ckpt_path is not None:
        cfg.model.ckpt_path = args.ckpt_path

    return cfg.dataset, cfg.pipeline, cfg.model

cfg = _ml3d.utils.Config.load_from_file(args.cfg_file)
cfg_dataset, cfg_pipeline, cfg_model = merge_cfg_file(cfg, args, None)

# cfg.dataset["dataset_path"] = args.dataset_path

Pipeline = _ml3d.utils.get_module("pipeline", cfg.pipeline.name, args.framework)
Model = _ml3d.utils.get_module("model", cfg.model.name, args.framework)
Dataset = _ml3d.utils.get_module("dataset", cfg.dataset.name)

dataset = Dataset(**cfg_dataset)
model = Model(**cfg_model)
pipeline = Pipeline(model, dataset, **cfg_pipeline)

# pprint.pprint(cfg_dataset)
# pprint.pprint(cfg_model)
# pprint.pprint(cfg_pipeline)

pipeline.cfg_tb = {
    "readme": "readme",
    "cmd_line": "cmd_line",
    "dataset": pprint.pformat(cfg_dataset, indent=2),
    "model": pprint.pformat(cfg_model, indent=2),
    "pipeline": pprint.pformat(cfg_pipeline, indent=2),
}
# pprint.pprint(pipeline.cfg_tb)

# train or test
if args.split == "test":
    pipeline.run_test()
else:
    pipeline.run_train()
sanskar107 commented 3 years ago

@tvkpz Thanks for reporting this issue. It is fixed in the latest release.