GithubHelp home page GithubHelp logo

Using Lambda layers to take different slices of a prevous layer's output causes earlier Lambda layers to be overwritten about tf-keras HOT 5 CLOSED

sachinprasadhs avatar sachinprasadhs commented on June 12, 2024
Using Lambda layers to take different slices of a prevous layer's output causes earlier Lambda layers to be overwritten

from tf-keras.

Comments (5)

qlzh727 avatar qlzh727 commented on June 12, 2024

@hosford42 who is the original reporter of the issue here.

from tf-keras.

qlzh727 avatar qlzh727 commented on June 12, 2024

I think the root cause here is the mix usage of lambda and for loop here, which is particularly errorprone.

The for loop cause the lambda function that captured by the lambda layer to be always the last loop step. You can actually verify this by visiting the labmda_layer.function.

If I change your model building function as below (without the for loop), it will actually run properly.

def slice_func_0_2(x):
  return x[..., 0:2]

def slice_func_2_5(x):
  return x[..., 2:5]


i = tf.keras.layers.Input((channels,), name='i')
o1 = tf.keras.layers.Lambda(slice_func_0_2, name="slice_0_2")(i)
o2 = tf.keras.layers.Lambda(slice_func_2_5, name="slice_2_5")(i)

o = [o1, o2]
m = tf.keras.Model(i, o, name='m')

from tf-keras.

qlzh727 avatar qlzh727 commented on June 12, 2024

I am closing this issue since this is a user code error. Feel free to reopen this if there is anything else we need to address.

In general, please take a look for https://gist.github.com/gisbi-kim/2e5648225cc118fc72ac933ef63c2d64 for pitfall for using lambda in a loop.

from tf-keras.

hosford42 avatar hosford42 commented on June 12, 2024

from tf-keras.

hosford42 avatar hosford42 commented on June 12, 2024

from tf-keras.

Related Issues (20)

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.