GithubHelp home page GithubHelp logo

neptune-ai / open-solution-salt-identification Goto Github PK

View Code? Open in Web Editor NEW
119.0 16.0 43.0 1.67 MB

Open solution to the TGS Salt Identification Challenge

Home Page: https://www.kaggle.com/c/tgs-salt-identification-challenge

License: MIT License

Python 89.18% Jupyter Notebook 10.71% Makefile 0.12%
deep-learning machine-learning data-science python python3 image-processing image-segmentation pytorch pipeline pipeline-framework

open-solution-salt-identification's Introduction

TGS Salt Identification Challenge

license

This is an open solution to the TGS Salt Identification Challenge.

Note

Unfortunately, we can no longer provide support for this repo. Hopefully, it should still work, but if it doesn't, we cannot really help.

More competitions ๐ŸŽ‡

Check collection of public projects ๐ŸŽ, where you can find multiple Kaggle competitions with code, experiments and outputs.

Our goals

We are building entirely open solution to this competition. Specifically:

  1. Learning from the process - updates about new ideas, code and experiments is the best way to learn data science. Our activity is especially useful for people who wants to enter the competition, but lack appropriate experience.
  2. Encourage more Kagglers to start working on this competition.
  3. Deliver open source solution with no strings attached. Code is available on our GitHub repository ๐Ÿ’ป. This solution should establish solid benchmark, as well as provide good base for your custom ideas and experiments. We care about clean code ๐Ÿ˜ƒ
  4. We are opening our experiments as well: everybody can have live preview on our experiments, parameters, code, etc. Check: TGS Salt Identification Challenge ๐Ÿ“ˆ or screen below.
Train and validation monitor ๐Ÿ“Š
training monitor

Disclaimer

In this open source solution you will find references to the neptune.ai. It is free platform for community Users, which we use daily to keep track of our experiments. Please note that using neptune.ai is not necessary to proceed with this solution. You may run it as plain Python script ๐Ÿ.

How to start?

Learn about our solutions

  1. Check Kaggle forum and participate in the discussions.
  2. See solutions below:
Link to Experiments CV LB Open
solution 1 0.413 0.745 True
solution 2 0.794 0.798 True
solution 3 0.807 0.801 True
solution 4 0.802 0.809 True
solution 5 0.804 0.813 True
solution 6 0.819 0.824 True
solution 7 0.829 0.837 True
solution 8 0.830 0.845 True
solution 9 0.853 0.849 True

Start experimenting with ready-to-use code

You can jump start your participation in the competition by using our starter pack. Installation instruction below will guide you through the setup.

Installation

Clone repository

git clone https://github.com/minerva-ml/open-solution-salt-identification.git

Set-up environment

You can setup the project with default env variables and open NEPTUNE_API_TOKEN by running:

source Makefile

I suggest at least reading the step-by-step instructions to know what is happening.

Install conda environment salt

conda env create -f environment.yml

After it is installed you can activate/deactivate it by running:

conda activate salt
conda deactivate

Register to the neptune.ai (if you wish to use it) even if you don't register you can still see your experiment in Neptune. Just go to shared/showroom project and find it.

Set environment variables NEPTUNE_API_TOKEN and CONFIG_PATH.

If you are using the default neptune.yaml config then run:

export export CONFIG_PATH=neptune.yaml

otherwise you can change to your config.

Registered in Neptune:

Set NEPTUNE_API_TOKEN variable with your personal token:

export NEPTUNE_API_TOKEN=your_account_token

Create new project in Neptune and go to your config file (neptune.yaml) and change project name:

project: USER_NAME/PROJECT_NAME

Not registered in Neptune:

open token

export NEPTUNE_API_TOKEN=eyJhcGlfYWRkcmVzcyI6Imh0dHBzOi8vdWkubmVwdHVuZS5tbCIsImFwaV9rZXkiOiJiNzA2YmM4Zi03NmY5LTRjMmUtOTM5ZC00YmEwMzZmOTMyZTQifQ==

Create data folder structure and set data paths in your config file (neptune.yaml)

Suggested directory structure:

project
|--   README.md
|-- ...
|-- data
    |-- raw
         |-- train 
            |-- images 
            |-- masks
         |-- test 
            |-- images
         |-- train.csv
         |-- sample_submission.csv
    |-- meta
        โ”‚-- depths.csv
        โ”‚-- metadata.csv # this is generated
        โ”‚-- auxiliary_metadata.csv # this is generated
    |-- stacking_data
        |-- out_of_folds_predictions # put oof predictions for multiple models/pipelines here
    |-- experiments
        |-- baseline # this is where your experiment files will be dumped
            |-- checkpoints # neural network checkpoints
            |-- transformers # serialized transformers after fitting
            |-- outputs # outputs of transformers if you specified save_output=True anywhere
            |-- out_of_fold_train_predictions.pkl # oof predictions on train
            |-- out_of_fold_test_predictions.pkl # oof predictions on test
            |-- submission.csv
        |-- empty_non_empty 
        |-- new_idea_exp 

in neptune.yaml config file change data paths if you decide on a different structure:

  # Data Paths
  train_images_dir: data/raw/train
  test_images_dir: data/raw/test
  metadata_filepath: data/meta/metadata.csv
  depths_filepath: data/meta/depths.csv
  auxiliary_metadata_filepath: data/meta/auxiliary_metadata.csv
  stacking_data_dir: data/stacking_data

Run experiment based on U-Net:

Prepare metadata:

python prepare_metadata.py

Training and inference. Everything happens in main.py. Whenever you try new idea make sure to change the name of the experiment:

EXPERIMENT_NAME = 'baseline'

to a new name.

python main.py

You can always change the pipeline you want ot run in the main. For example, if I want to run just training and evaluation I can change `main.py':

if __name__ == '__main__':
    train_evaluate_cv()

References

1.Lovash Loss

@InProceedings{Berman_2018_CVPR,
author = {Berman, Maxim and Rannen Triki, Amal and Blaschko, Matthew B.},
title = {The Lovรกsz-Softmax Loss: A Tractable Surrogate for the Optimization of the Intersection-Over-Union Measure in Neural Networks},
booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {June},
year = {2018}
}

Get involved

You are welcome to contribute your code and ideas to this open solution. To get started:

  1. Check competition project on GitHub to see what we are working on right now.
  2. Express your interest in paticular task by writing comment in this task, or by creating new one with your fresh idea.
  3. We will get back to you quickly in order to start working together.
  4. Check CONTRIBUTING for some more information.

User support

There are several ways to seek help:

  1. Kaggle discussion is our primary way of communication.
  2. Submit an issue directly in this repo.

open-solution-salt-identification's People

Contributors

jakubczakon avatar kant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

open-solution-salt-identification's Issues

GPU utilization is 0 most of the time

nvidia-smi gives 0% percentage GPU-Util most of the time(in offline mode). Am I doing something wrong? Using the same config file as in [solution-3]. CPU usage is high most of the time.

implemented hand-crafted architecture

The structure of the data is a bit different from your typical image problem:

  • depth can be used in the model
  • the image is build top-to-botton (that is why cumsum is often used)

TypeError: can't multiply sequence by non-int of type 'float' while training

I'm trying to run locally solution-3

Full stack of the error:

TypeError                                 Traceback (most recent call last)
<ipython-input-5-2da0ffaf5447> in <module>()
----> 1 train()

<ipython-input-3-0a8b44c1d62a> in train()
    314     pipeline_network = unet(config=CONFIG, train_mode=True)
    315     pipeline_network.clean_cache()
--> 316     pipeline_network.fit_transform(data)
    317     pipeline_network.clean_cache()
    318 

~/anaconda3/lib/python3.6/site-packages/steppy/base.py in fit_transform(self, data)
    321             else:
    322                 step_inputs = self._unpack(step_inputs)
--> 323             step_output_data = self._cached_fit_transform(step_inputs)
    324         return step_output_data
    325 

~/anaconda3/lib/python3.6/site-packages/steppy/base.py in _cached_fit_transform(self, step_inputs)
    441             else:
    442                 logger.info('Step {}, fitting and transforming...'.format(self.name))
--> 443                 step_output_data = self.transformer.fit_transform(**step_inputs)
    444                 logger.info('Step {}, persisting transformer to the {}'
    445                             .format(self.name, self.exp_dir_transformers_step))

~/anaconda3/lib/python3.6/site-packages/steppy/base.py in fit_transform(self, *args, **kwargs)
    603             dict: outputs
    604         """
--> 605         self.fit(*args, **kwargs)
    606         return self.transform(*args, **kwargs)
    607 

~/Desktop/ml/salt/open-solution-salt-identification-master/common_blocks/models.py in fit(self, datagen, validation_datagen, meta_valid)
     61             self.model = self.model.cuda()
     62 
---> 63         self.callbacks.set_params(self, validation_datagen=validation_datagen, meta_valid=meta_valid)
     64         self.callbacks.on_train_begin()
     65 

~/Desktop/ml/salt/open-solution-salt-identification-master/common_blocks/callbacks.py in set_params(self, *args, **kwargs)
     89     def set_params(self, *args, **kwargs):
     90         for callback in self.callbacks:
---> 91             callback.set_params(*args, **kwargs)
     92 
     93     def on_train_begin(self, *args, **kwargs):

~/Desktop/ml/salt/open-solution-salt-identification-master/common_blocks/callbacks.py in set_params(self, transformer, validation_datagen, *args, **kwargs)
    235         self.optimizer = transformer.optimizer
    236         self.loss_function = transformer.loss_function
--> 237         self.lr_scheduler = ExponentialLR(self.optimizer, self.gamma, last_epoch=-1)
    238 
    239     def on_train_begin(self, *args, **kwargs):

~/anaconda3/lib/python3.6/site-packages/torch/optim/lr_scheduler.py in __init__(self, optimizer, gamma, last_epoch)
    155     def __init__(self, optimizer, gamma, last_epoch=-1):
    156         self.gamma = gamma
--> 157         super(ExponentialLR, self).__init__(optimizer, last_epoch)
    158 
    159     def get_lr(self):

~/anaconda3/lib/python3.6/site-packages/torch/optim/lr_scheduler.py in __init__(self, optimizer, last_epoch)
     19                                    "in param_groups[{}] when resuming an optimizer".format(i))
     20         self.base_lrs = list(map(lambda group: group['initial_lr'], optimizer.param_groups))
---> 21         self.step(last_epoch + 1)
     22         self.last_epoch = last_epoch
     23 

~/anaconda3/lib/python3.6/site-packages/torch/optim/lr_scheduler.py in step(self, epoch)
     29             epoch = self.last_epoch + 1
     30         self.last_epoch = epoch
---> 31         for param_group, lr in zip(self.optimizer.param_groups, self.get_lr()):
     32             param_group['lr'] = lr
     33 

~/anaconda3/lib/python3.6/site-packages/torch/optim/lr_scheduler.py in get_lr(self)
    159     def get_lr(self):
    160         return [base_lr * self.gamma ** self.last_epoch
--> 161                 for base_lr in self.base_lrs]
    162 
    163 

~/anaconda3/lib/python3.6/site-packages/torch/optim/lr_scheduler.py in <listcomp>(.0)
    159     def get_lr(self):
    160         return [base_lr * self.gamma ** self.last_epoch
--> 161                 for base_lr in self.base_lrs]
    162 
    163 

TypeError: can't multiply sequence by non-int of type 'float'

SO suggest to convert list to numpy this way np.asarray(coff) * C

  • but actually I'm kind confused where to apply it

Problem with submission.csv

There is problem with submission.csv file as kaggle is not accepting the file and showing error

Evaluation Exception: Index was outside the bounds of the array.

There might be some problem with rle encoding

Can not find the 'metadata.csv'

When I run the command 'python main.py -- train--pipeline_name unet', I got the error "Can not find the 'metadata.csv'" . I checked all the files of salt-detection and still can not find it. Did I miss something important?

Confusion Matrix

As per the discussions on Kaggle, yours implementation is the only implementation that is fully correct for the given metric but there is one thing that I couldn't understand as per your code. Here are these three functions:

def compute_ious(gt, predictions):
    gt_ = get_segmentations(gt)
    predictions_ = get_segmentations(predictions)

    if len(gt_) == 0 and len(predictions_) == 0:
        return np.ones((1, 1))
    elif len(gt_) != 0 and len(predictions_) == 0:
        return np.zeros((1, 1))
    else:
        iscrowd = [0 for _ in predictions_]
        ious = cocomask.iou(gt_, predictions_, iscrowd)
        if not np.array(ious).size:
            ious = np.zeros((1, 1))
        return ious


def compute_precision_at(ious, threshold):
    mx1 = np.max(ious, axis=0)
    mx2 = np.max(ious, axis=1)
    tp = np.sum(mx2 >= threshold)
    fp = np.sum(mx2 < threshold)
    fn = np.sum(mx1 < threshold)
    return float(tp) / (tp + fp + fn)

def compute_eval_metric(gt, predictions):
    thresholds = [0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95]
    ious = compute_ious(gt, predictions)
    precisions = [compute_precision_at(ious, th) for th in thresholds]
    return sum(precisions) / len(precisions)

Now, given the fact that compute_ious function works on a single prediction and it's corresponding groundtruth, ious will be a singleton array. Then, how are you calculating TP/FP from that? Am I missing something here?

experiment with adding depth channel to the image

add normalized depth channel where first row has all values equal to 0 and 101 row has all values equal to 1. Potentially one more channel where we multiply pixel value and normalized depth is a good idea too.

Cannot find the 'metadata.csv'

After run the code, I'm sorry to find 'metadata.csv' does not exist. And I could not find it in the homepage of TGS. I was wondering how to solve this problem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.