GithubHelp home page GithubHelp logo

Comments (8)

Shathe avatar Shathe commented on June 11, 2024

This repository is just an example (not a tutorial) that's why I did not commented anything about my Loader class.

The Loader class, loads the image labels but, they need to have values from 0 to the number of classes - 1. That is: if You have 2 classes the labels must be 0 and 1. If you have 10 classes, the labels must be 0,1,2,3,4,5,6,7,8,9.
Other label values will be ignore (new commit, pull new changes)

I think the values are 0 and 255 so -> Please change the 255 values to 1's.

Another thing to change is the number of classes. You have two classes not one. It's a binary problem. You have the class of "that's a thing I want to segment" and the class of "that is not the thing I want to segment"

from semantic-segmentation-tensorflow-eager.

rafaelmarconiramos avatar rafaelmarconiramos commented on June 11, 2024

Thanks. I changed the code start, but now generate another error:

Traceback (most recent call last):
File "train_eager_seg.py", line 109, in
train(loader=loader, model=model, epochs=20, batch_size=8)
File "train_eager_seg.py", line 50, in train
loss = tf.losses.softmax_cross_entropy(y, y_, weights=mask)
File "/home/rafaelmr/.conda/envs/seg1/lib/python2.7/site-packages/tensorflow/python/ops/losses/losses_impl.py", line 793, in softmax_cross_entropy
logits.get_shape().assert_is_compatible_with(onehot_labels.get_shape())
File "/home/rafaelmr/.conda/envs/seg1/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.py", line 847, in assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (8, 160, 160, 2) and (8, 140, 140, 2) are incompatible

All images are 140x140, and I configured the parameters for that size.
Why the model generates a shape like (8, 160, 160, 2)?
Do I need to know something more about the data? Or the model?
I looked for in the project files, but I didn´t find.

Thanks for your attention.

from semantic-segmentation-tensorflow-eager.

Shathe avatar Shathe commented on June 11, 2024

That is something concerning your code and yes, it's about sizes/shapes

Somewhere you must have specified the 160x160 (at code level) or the images are 140x140.

The image size is specified here https://github.com/Shathe/Semantic-Segmentation-Tensorflow-Eager/blob/master/train_eager.py#L100

The network input shape (input_shape parameter) here https://github.com/Shathe/Semantic-Segmentation-Tensorflow-Eager/blob/master/train_eager.py#L104

Please, take your time to code and to debug the code

from semantic-segmentation-tensorflow-eager.

rafaelmarconiramos avatar rafaelmarconiramos commented on June 11, 2024

Sorry.

In this line generates the problem:

y_ = model(x, training=True)

x,y, mask are tf.Tensor(shape=(8, 140, 140, 2), dtype=uint8)
y_ is tf.Tensor(shape=(8, 160, 160, 2), dtype=float32)

I will try to understand what the line 48 do.

from semantic-segmentation-tensorflow-eager.

Shathe avatar Shathe commented on June 11, 2024

y_ is the output, so the output has that size.
I cannot help more without seen your edited code.

from semantic-segmentation-tensorflow-eager.

rafaelmarconiramos avatar rafaelmarconiramos commented on June 11, 2024

With the architecture of MnasnetFC, the code works just with the image sizes that are multiples of 32.
Look the shapes of your example (each execution of the out in MnasnetFC.call)
initial: (8, 112, 112, 32)
initial2: (8, 112, 112, 32)
initial3: (8, 112, 112, 32)
initial4: (8, 112, 112, 32)
initial5: (8, 112, 112, 16)
blocks: (8, 56, 56, 24)
blocks: (8, 56, 56, 24)
blocks: (8, 56, 56, 24)
blocks: (8, 28, 28, 40)
blocks: (8, 28, 28, 40)
blocks: (8, 28, 28, 40)
blocks: (8, 14, 14, 80)
blocks: (8, 14, 14, 80)
blocks: (8, 14, 14, 80)
blocks: (8, 14, 14, 96)
blocks: (8, 14, 14, 96)
blocks: (8, 7, 7, 192)
blocks: (8, 7, 7, 192)
blocks: (8, 7, 7, 192)
blocks: (8, 7, 7, 192)
blocks: (8, 7, 7, 320)
initial6: (8, 7, 7, 1152)
up: (8, 14, 14, 1152)
up: (8, 14, 14, 192)
up: (8, 14, 14, 192)
up: (8, 28, 28, 192)
up: (8, 28, 28, 80)
up: (8, 28, 28, 80)
up: (8, 56, 56, 80)
up: (8, 56, 56, 40)
up: (8, 112, 112, 40)
up: (8, 112, 112, 24)
up: (8, 224, 224, 24)
final: (8, 224, 224, 11)

Basic it decreases the shape dividing by two. After it increases the shape multiplying by two. It does this operation five times then it needs a multiply of 32.
In my case the division by two has rest then when it executes the multiplication don´t finish with correct number.

initial: (8, 70, 70, 32)
initial2: (8, 70, 70, 32)
initial3: (8, 70, 70, 32)
initial4: (8, 70, 70, 32)
initial5: (8, 70, 70, 16)
blocks: (8, 35, 35, 24)
blocks: (8, 35, 35, 24)
blocks: (8, 35, 35, 24)
blocks: (8, 18, 18, 40)
blocks: (8, 18, 18, 40)
blocks: (8, 18, 18, 40)
blocks: (8, 9, 9, 80)
blocks: (8, 9, 9, 80)
blocks: (8, 9, 9, 80)
blocks: (8, 9, 9, 96)
blocks: (8, 9, 9, 96)
blocks: (8, 5, 5, 192)
blocks: (8, 5, 5, 192)
blocks: (8, 5, 5, 192)
blocks: (8, 5, 5, 192)
blocks: (8, 5, 5, 320)
initial6: (8, 5, 5, 1152)
up: (8, 10, 10, 1152)
up: (8, 10, 10, 192)
up: (8, 10, 10, 192)
up: (8, 20, 20, 192)
up: (8, 20, 20, 80)
up: (8, 20, 20, 80)
up: (8, 40, 40, 80)
up: (8, 40, 40, 40)
up: (8, 80, 80, 40)
up: (8, 80, 80, 24)
up: (8, 160, 160, 24)
final: (8, 160, 160, 2)

Correct?
My code:
if name == "main":

    n_classes = 2
    dataset_path = 'seg'
    loader = Loader.Loader(dataFolderPath=dataset_path, n_classes=n_classes, problemType='segmentation', width=140,
                    height=140, ignore_label=n_classes)

    # build model and optimizer
    model = MnasnetEager.MnasnetFC(num_classes=n_classes)

    # optimizer
    optimizer = tf.train.AdamOptimizer(0.001)

    train(loader=loader, model=model, epochs=20, batch_size=8)
    get_params(model)

from semantic-segmentation-tensorflow-eager.

Shathe avatar Shathe commented on June 11, 2024

Mmmm My Loader automatically resize the images to the specified size so although your images are 140, try to set the size to 224 or to 112

from semantic-segmentation-tensorflow-eager.

Shathe avatar Shathe commented on June 11, 2024

Have you tried it?

from semantic-segmentation-tensorflow-eager.

Related Issues (12)

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.