Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    raftaa
    @raftaa
    hi, one question concerning restricting GPU performance of TF: In Python we managed to restrict the GPU memory of our TF process to a certain amount of the GPU menory with: " tf.config.set_logical_device_configuration(gpu, [tf.config.LogicalDeviceConfiguration(memory_limit=8192)])". In Java we tried to use setPerProcessGpuMemoryFraction to restrict it to 50%. The configuration in java is implemented as follows:
    GPUOptions gpu = ConfigProto.getDefaultInstance().getGpuOptions().toBuilder().setPerProcessGpuMemoryFraction(0.5).setAllowGrowth(true).build();
    ConfigProto config = ConfigProto.newBuilder(ConfigProto.getDefaultInstance()).setLogDevicePlacement(true).mergeGpuOptions(gpu).build();
    However, it doesn't work and we get an exception: org.tensorflow.exceptions.TensorFlowException: 2 root error(s) found.
    (0) Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, [...]
    Adam Pocock
    @Craigacp
    Could you post the full error message in a github issue?
    raftaa
    @raftaa
    I just created tensorflow/java#383 concerning the issue I mentioned above
    Adam Pocock
    @Craigacp
    Ok thanks, we'll follow up there.
    raftaa
    @raftaa
    I just noticed that the GPU memory is allocated when loading a model with "SavedModelBundle.load(...)". The GPUOptions in the ConfigProto are used later when opening a session e.g. to classify an image (at least in our code). How is this meant to be done? How can I set the GPU options before loading a model?
    raftaa
    @raftaa
    Ahhh... okay, now it works. It just placed the code to load the model after creating a session with the gpu parameters.
    Adam Pocock
    @Craigacp
    You should be able to supply the ConfigProto to the SavedModelBundle loader which should do that directly. I'd missed the SavedModelBundle part of your issue.
    raftaa
    @raftaa
    Yes, I see: SavedModelBundle.loader(tensorflowModelPath).withConfigProto(configProto).. thanks a lot, Adam. Sorry for the dumb questions.
    Adam Pocock
    @Craigacp
    No worries, it's not got the best documentation.
    Michael Kilian
    @deluxeomat
    Hi folks, just a question, is there a way to attach the tensorflow logging output to my log4j file logger?
    In python, i was able to pass my "log handler" with "tf.get_logger().addHandler(logHandler)" to receive all log events into my file logger.
    Now I'm searching for a simular solution in Java to log all the Tensorflow events.
    Adam Pocock
    @Craigacp
    It's being worked on but needs fixes in the TensorFlow C API.
    Karl Lessard
    @karllessard
    Hi everyone, just to announce that the latest 0.4.0 snapshots are now based on TF 2.6.0. For those who want to try it, let us know how it goes, thanks!
    tanzhenyu
    @tanzhenyu
    Good to know ConcreteFunction is now supported! Is that executing the same code path as what a traditional session.run(..., {'StatefulPartitionedCall'}, ...) does?
    Ryan Nett
    @rnett
    Yeah, that's what it uses internally. Although statefulness is determined by what's in the function
    Hanns Holger Rutz
    @Sciss
    Hi there. is tensorflow-java the best way to work with tensorflow in Scala, or are there alternative projects that be better suited to have direct Scala bindings?
    Adam Pocock
    @Craigacp
    I think it's the only one under active development. This project (https://github.com/eaplatanios/tensorflow_scala) has Scala bindings to the C API directly, but hasn't been updated to track newer versions of TensorFlow and I'm not sure of it's status.
    Hanns Holger Rutz
    @Sciss
    Ok, thanks. I'll check out both.
    Anthony Platanios
    @eaplatanios
    Hi! I’m behind tf-scala referenced above. It’s true that I haven’t updated the library in a while because I don’t have much free time, but it does work with TF 2.4 currently and we are also using it in production, so it’s reasonably stable.
    Karl Lessard
    @karllessard
    On that @eaplatanios , do you think it could be interesting to « merge » tf-scala in tf-java so you won’t have to maintain a separate project by yourself? Are you aware of any important feature currently missing in tf-java, but present in tf-scala, that would enhance user experience for Scala developers?
    Hanns Holger Rutz
    @Sciss
    Thank you, it's good to hear that.
    Hanns Holger Rutz
    @Sciss

    HI there. Are there any self-contained example projects to look at? I'm trying this, using sbt 1.5.5:

    lazy val deps = new {
      val tensorflow = "0.3.3"
    }
    
    lazy val root = project.in(file("."))
      .settings(
        scalaVersion := "3.0.2",
        libraryDependencies ++= Seq(
          "org.tensorflow" % "tensorflow-core-api"  % deps.tensorflow,
          "org.tensorflow" % "tensorflow-core-api"  % deps.tensorflow classifier "linux-x86_64-mkl",
          "org.tensorflow" % "tensorflow-framework" % deps.tensorflow,
        )
      )

    and

    package de.sciss.tf
    
    import org.tensorflow.EagerSession
    
    object Test:
      def main(args: Array[String]): Unit =
        val input   = Array(-10.0, -5.0, 0.0, 5.0, 10.0)
        val options = EagerSession.options()
        val session = EagerSession.initDefault(options)
        println("Here")
        session.close()

    But running it just tells me something for JNI isn't working yet:

    Warning: Could not load Loader: java.lang.UnsatisfiedLinkError: no jnijavacpp in java.library.path: [/usr/java/packages/lib, /usr/lib/x86_64-linux-gnu/jni, /lib/x86_64-linux-gnu, /usr/lib/x86_64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
    Warning: Could not load Pointer: java.lang.UnsatisfiedLinkError: no jnijavacpp in java.library.path: [/usr/java/packages/lib, /usr/lib/x86_64-linux-gnu/jni, /lib/x86_64-linux-gnu, /usr/lib/x86_64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
    Warning: Could not load BytePointer: java.lang.UnsatisfiedLinkError: no jnijavacpp in java.library.path: [/usr/java/packages/lib, /usr/lib/x86_64-linux-gnu/jni, /lib/x86_64-linux-gnu, /usr/lib/x86_64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
    2021-10-03 16:07:13.749139: I external/org_tensorflow/tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
    To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
    2021-10-03 16:07:13.749982: I external/org_tensorflow/tensorflow/core/common_runtime/process_util.cc:146] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
    Here
    Exception in thread "main" java.lang.IllegalStateException: Default eager session cannot be closed
        at org.tensorflow.EagerSession.close(EagerSession.java:261)
        at de.sciss.tf.Test$.main(Test.scala:11)
        at de.sciss.tf.Test.main(Test.scala)
    Like a Java example showing simple cycle of training an ANN, then creating some predictions.
    Hanns Holger Rutz
    @Sciss
    Trying to work through this tutorial https://www.baeldung.com/tensorflow-java - but Tensor.create seems to no longer exist. How do you create a constant scalar in the current version?
    and there is a more type safe API than stringly typed opBuilder?
    Hanns Holger Rutz
    @Sciss
    Ok, getting the hang of it. Is this the idiomatic way?
    val g       = new Graph()
    val ops     = Ops.create(g)
    import ops.*
    val a       = constant(3.0)
    val b       = constant(2.0)
    val x       = placeholder(classOf[TFloat64])
    val y       = placeholder(classOf[TFloat64])
    val ax      = math.mul(a, x)
    val by      = math.mul(b, y)
    val z       = math.add(ax, by)
    val session = new Session(g)
    val r       = session.runner()
    val tensor  = r.fetch(z)
      .feed(x, TFloat64.scalarOf(3.0))
      .feed(y, TFloat64.scalarOf(6.0))
      .run
      .get(0)
    
    tensor match
      case tf: TFloat64 => println(tf.getDouble())  // 21.0
      case other        => println(s"OTHER: $other")
    Adam Pocock
    @Craigacp
    The examples repo is here https://github.com/TensorFlow/java-models
    That tutorial is for the old 1
    1.x API. The tests in the TensorFlow Java repo are the most up to date way of doing things. Note at the moment there's an issue with gradient determinism when building models for training that causes incorrect outputs occasionally.
    We are working on a higher level API, but it's not all available yet
    Hanns Holger Rutz
    @Sciss
    thanks. I think with a bit of Scala facade, this already looks quite nice and concise.
    Hanns Holger Rutz
    @Sciss
    Is it possible to use keras API, e.g. https://www.tensorflow.org/tutorials/generative/dcgan ? or do I have to translate that back to plain TF ?
    Adam Pocock
    @Craigacp
    We're working on the higher level API, which will be Keras like, but the model and layer apis are not integrated yet.
    Hanns Holger Rutz
    @Sciss
    Ok, I'm trying to update an older keras wrapper project, it uses the old Java API. What this the new way of writing Tensors.create(float[][])?
    Hanns Holger Rutz
    @Sciss
    I can create 1D vector with TFloat32.vectorOf, but 2D?
    Tensor.of(TFloat32.class, Shape.of(javaArray.length, javaArray[0].length), data -> StdArrays.copyTo(javaArray, data)) I guess ... ? Is there a utility function that does this?
    Hanns Holger Rutz
    @Sciss

    I'm stuck with these:

    public class Ones {
        public <T extends TNumber> Operand<T> initialize(Ops tf, Operand<TInt32> shape, Class<T> dtype) {
            return tf.fill(shape, tf.constant(1.0f, dtype));   // no such method
        }
    }

    How can I convert from a float to a TNumber? In Scala this would be a type class instance TNumbers[T <: TNumber] { def fromFloat(f: Float): Operand[T] }, but I don't know how to express that in Java. Should I change Class<T> for something that has factory capabilities?

    Adam Pocock
    @Craigacp
    Off the top of my head you could use tf.cast.
    Karl Lessard
    @karllessard

    To create a 2D tensor from a 2D java array, you can invoke TFloat32.tensorOf(StdArrays.ndCopyOf(javaArray)).

    If you are looking to create a constant though, there is a shortcut function that allows you to do simply tf.constant(javaArray)

    If you can avoid completely the use of standard Java arrays and only rely on the NdArray hierarchy from the start, you’ll have better performances and memory usage
    Hanns Holger Rutz
    @Sciss
    I see, thanks. For now, I'm just trying to make somebody else's library compile ;)
    This does compile indeed tf.fill(shape, tf.dtypes.cast(tf.constant(1.0f), dtype)). So it won't fail at runtime?
    raftaa
    @raftaa
    Hi, I have a question concerning saving/exporting/loading a model for deployment. I think I want something like a frozen graph of my model i.e. one single pb file. I used tf.io.write_graph in python to write my model into a pb file. However when trying to load it in Java via SavedModelLoader.loader(pb_file_directory) I get an exception: "Could not find meta graph def matching supplied tags: { serve }. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: saved_model_cli". And saved_model_cli tells me that "SavedModel file does not exist" in that directory. I'm confused and my question is: how is this usually done and what works for TF java?
    Adam Pocock
    @Craigacp
    If you've got a frozen graph you can load that directly by reading it into a GraphDef and supplying that to the Graph before making a session. That's not how TF 2 (or even later versions of TF 1) do deployment, they use SavedModels which is a folder containing a graph pb and a checkpoint pb of the variables.
    TF-Java uses SavedModelBundle to load in saved models.
    raftaa
    @raftaa
    I understand. Thanks Adam!
    Hanns Holger Rutz
    @Sciss

    Trying to translate this tutorial. Python:

    noise = tf.random.normal([1, 100])

    How do I write that in Java/Scala? I try

    val noise = tf.random.randomStandardNormal(Shape.of(1, 100), classOf[TFloat32])

    But this is not an Operand[? <: TNumber]. How I get from Shape to that?

    Is tf.constant(Array(1, 100)) correct?