profile
viewpoint

34rth/tron 1

Tron node

cefaci/super-simple-pg-dao 0

Simple Nodejs PG DAO

cefaci/tensorflow 0

An Open Source Machine Learning Framework for Everyone

issue commenttensorflow/models

Evaluation/Finetuning of Resnet 50 in TF 2.X

@allenwang28 Thanks for this, could finally train on the TPU and export as tflite

peri044

comment created time in a month

issue commenttensorflow/tensorflow

TFLite: C++/Java: experimental kernel ctc_beam_search_decoder returns always buffer length=length+1

  • "I mean why python gives you a 2-d tensor while the java gives you a 1-d tensor?": If I increase the batch size the next result will be just appended to the IntBuffer: [20, 11, 47, 12, 47, 27, 26, 26, 26, 20, 11, 47, 12, 47, 27, 26, 26, 26, 0, 0, 0, 0]
  • The last zero is my fault, I checked the complete returned result, e.g. Arrays.copyOfRange(b.array(), b.arrayOffset(), b.array().length);

Many thanks for your help and sorry!!

cefaci

comment created time in 2 months

issue closedtensorflow/tensorflow

TFLite: C++/Java: experimental kernel ctc_beam_search_decoder returns always buffer length=length+1

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Pixel 2
  • TensorFlow installed from (source or binary): source
  • TensorFlow version: master
  • Python version: 3.8
  • Installed using virtualenv? pip? conda?: pip
  • Bazel version (if compiling from source): 3.1.0
  • GCC/Compiler version (if compiling from source): 9.3.0
  • CUDA/cuDNN version: -
  • GPU model and memory: -
  • NDK: android-ndk-r20

Describe the current behavior All returned Java IntBuffer (TFLite Android) from the concrete function ( decoder.tflite) have an extra added byte=0 in the end of the returned dense_decoded, e.g. [11,11,4,7,8,0]. => This happens only in TFLite with the tflite experimental kernel ctc_beam_search_decoder.cc returned from Java.

Describe the expected behavior The returned dense_decoded from the concrete function ( decoder.tflite) should be e.g. [11,11,4,7,8]. => If I use the concrete function directly in python it works as expected => If I use the concrete function exported as decoder.tflite and loaded directly in python it works as expected.

Standalone code to reproduce the issue

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout -b master 6e9d916229b5aefbdcfd33cbc4b34c9f48b5e6e1
nano .tf_configure.bazelrc

Bazel config .tf_configure.bazelrc:

build --action_env PYTHON_BIN_PATH="/usr/bin/python"
build --action_env PYTHON_LIB_PATH="/usr/lib/python3/dist-packages"
build --python_path="/usr/bin/python"
build:xla --define with_xla_support=true
build:opt --copt=-march=native
build:opt --copt=-Wno-sign-compare
build:opt --host_copt=-march=native
build:opt --define with_default_optimizations=true
build --action_env ANDROID_NDK_HOME="CHANGE_TO_YOUR_ANDROID_NDK_HOME"
build --action_env ANDROID_NDK_API_LEVEL="21"
build --action_env ANDROID_BUILD_TOOLS_VERSION="28.0.0"
build --action_env ANDROID_SDK_API_LEVEL="23"
build --action_env ANDROID_SDK_HOME="CHANGE_TO_YOUR_ANDROID_SDK_HOME"
test --flaky_test_attempts=3
test --test_size_filters=small,medium
test --test_tag_filters=-benchmark-test,-no_oss,-oss_serial
test --build_tag_filters=-benchmark-test,-no_oss
test --test_tag_filters=-gpu
test --build_tag_filters=-gpu
build --action_env TF_CONFIGURE_IOS="0"

And compile with

bazel build --cxxopt='--std=c++14' -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a --config=monolithic \
  --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
  //tensorflow/lite/java:tensorflow-lite \
  //tensorflow/lite/java:tensorflow-lite-gpu \
  //tensorflow/lite/delegates/flex:delegate \
  //tensorflow/lite/experimental/kernels:ctc_beam_search_decoder_op \
  //tmp:tensorflow-lite-select-tf-ops

Concrete function exported to decoder.tflite:

@tf.function
def decode(logits, top_paths=3, beam_width=3):
    batch_size_current, timesteps, _ = tf.shape(input=logits)
    seq_len = tf.fill([batch_size_current], timesteps)
    logits = tf.transpose(a=logits, perm=(1, 0, 2))

    decoded, log_probabilities = tf.nn.ctc_beam_search_decoder(inputs=logits, top_paths=top_paths, beam_width=beam_width, sequence_length=seq_len)

    dense_decoded = tf.sparse.to_dense(decoded[0], default_value=-1)

closed time in 2 months

cefaci

issue commenttensorflow/tensorflow

TFLite: C++/Java: experimental kernel ctc_beam_search_decoder returns always buffer length=length+1

No it is good, it is how you retrieve it in java and the batchsize is here set to 1. The last zero is wrong and differs from the same python output, the length should be both 9 as well and not an extra added zero in the end:

[ 20 11 47 12 47 27 26 26 26] != 
[20, 11, 47, 12, 47, 27, 26, 26, 26, 0]
cefaci

comment created time in 2 months

issue commenttensorflow/tensorflow

TFLite: C++/Java: experimental kernel ctc_beam_search_decoder returns always buffer length=length+1

You're welcome, yeah top_paths is set to 3 and originally I returned all 3, just get the first one:

public static IntBuffer[] run(Interpreter interpreter, int length, float[][][] outputLogits){
    try {
        Object[] inputs = {outputLogits, new int[]{1}}; // batch size 1
        Map<Integer, Object> outputs = new HashMap<>();

        ByteBuffer buffer = ByteBuffer.allocateDirect(length * 4);//int32
        buffer.order(ByteOrder.nativeOrder());
        IntBuffer output = buffer.asIntBuffer();
        outputs.put(0, output);

        interpreter.runForMultipleInputsOutputs(inputs, outputs);
        return output;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

cefaci

comment created time in 2 months

issue commenttensorflow/tensorflow

TFLite: C++/Java: experimental kernel ctc_beam_search_decoder returns always buffer length=length+1

So the decoder.tflite model is:

class Decode(tf.keras.Model):
    @tf.function(input_signature=[tf.TensorSpec(shape=[None, IMG_SIZE[1], NUM_CLASS], dtype=IMAGE_TYPE_TF_TEST), tf.TensorSpec(shape=[None,], dtype=tf.int32)]) 
    def decode(self, logits, batch_size, top_paths=3, beam_width=3):
        batch_size_current, timesteps, _ = logits.get_shape()
        batch_size = batch_size[0]
        seq_len = tf.fill([batch_size], timesteps)
        logits = tf.transpose(a=logits, perm=(1, 0, 2))

        decoded, log_probabilities = tf.nn.ctc_beam_search_decoder(inputs=logits, top_paths=top_paths, beam_width=beam_width, sequence_length=seq_len)

        dense_decoded = tf.sparse.to_dense(decoded[0], default_value=-1)

        return dense_decoded

Python

The tensor used in python (shape=(1, 24, 49), dtype=float32) against the decoder.tflite model:

tf.Tensor(
[[[ -1.1646128     -3.7951221     -1.0731119     -5.230322    -4.3759046     -1.1051129     -5.9621816     -2.1139586    -1.6347717     -3.0709565      0.25088528    -4.5464454     0.9719744     -2.6028876     -5.2125697     -4.693067    -3.4992895     -6.196344      -1.9408542     -1.8609589    -5.123465      -2.1778982     -0.3016574     -1.4162496    -0.05596298    -3.3783443     -4.0272593     -3.7445364    -0.0028205316  -0.8726251     -2.6476762     -2.7670584    -3.531002      -2.86586       -3.0021574      1.9833964    -6.5366592     -4.3795114     -9.089881      -2.9438267    -2.824938      -8.183831      -5.9174848    -15.839222    -8.734572     -10.726117      -9.316691       4.295628    18.199356    ]
  [ -0.031096319   -3.871109      -1.1181607     -2.0011232    -4.7141924     -1.2818102     -4.978454       2.0263755    -0.21877344    -0.46911952     1.3215663     -2.7769063     3.4695244     -1.7167692     -4.468163      -3.00177    -3.4645154     -4.2073197     -5.397524      -0.36775938    -4.821177      -1.638662       0.23415852    -1.3846282    -2.6762388     -4.1896615     -1.411914      -2.8303812     1.251152       0.5686881     -0.6898544     -2.794163    -4.0943656     -2.028222      -4.0183196      2.4679868    -2.5596936     -1.7351736     -5.4891076     -1.3824191    -2.1094246     -2.8548317     -3.896057     -13.179549    -8.732274      -8.050248      -7.7822146      1.5458045    20.359257    ]
  [  1.2163008     -2.6954525     -0.86427027     0.6024355    -6.1996074     -3.0337527     -3.3046398      2.9629385     3.3836906      0.6956072     -0.5831372      0.26549777     2.1988766      0.034438375   -1.2926706     -3.415465    -1.8027607     -4.706817      -2.7042725      1.7454389    -1.63372       -2.0432458      0.5463361     -2.4805515    -3.2112253     -3.8260605     -2.330295       0.48245263    -2.5352879     -1.9981833     -3.6866705     -4.316192    -4.7724094     -3.8186944     -6.9987373      0.83749133    -5.358316      -3.382599      -3.0282784     -1.8950666    -4.312699      -0.3736072     -5.263495     -11.096023   -10.782363      -8.377029      -9.81446       -0.5631078    18.654766    ]
  [  1.6706834     -2.135751      -2.6569047      1.4258738    -3.101607      -7.347342      -6.336166      -0.92469734     3.8745248     -0.68873376    -2.5481994      3.0339756     0.019852579    2.4946487     -3.264964      -9.122855    -0.5293837     -3.387656      -6.479887      -0.41217116     2.1036355     -5.3812556     -4.8552337     -4.6979804    -6.1752295     -3.2327073     -3.25391       -1.0128698    -4.135406      -8.941207      -3.8629827     -5.694706    -7.9600415     -6.6381497     -7.7798233     -4.398782    -5.243107      -6.0830593      3.9232616     -4.3167377    -3.767523      -3.2243702     -5.2422233     -9.081962    -9.653151      -6.1841607     -6.414804       3.442686    16.106243    ]
  [  2.5365763     -0.3145837      6.921036       5.1193705     1.4797157     -8.922007       2.5846255      1.3787552     3.09406    9.555295      -2.7645082     15.209727    -2.015432      -3.7025976      4.959807      -5.207284     0.76611304    -3.6603796      3.0620315     -6.1943145    18.713396      -1.9181551     -0.14312221    -3.73462    -5.586571       4.035087       6.6243644     -4.5170846    -2.1310537     -4.0330253      3.1677713     -0.8995264     0.41301596    -2.8552415     -1.0611678     -2.8348706    -7.8290887     -1.8352652      7.9356976     -6.084311    -6.470459      -0.59961814    -2.9941504     -5.9037833    -8.757953      -8.05204       -7.22634       -2.3976681     5.6136956   ]
  [  0.86832124    -4.314832      -1.1376096     -1.2795423     0.89594346    -3.2714832     -4.813009      -3.6954434     6.292471       1.9540067     -1.269824       3.7818973     1.2630774      2.311032      -3.6972969     -8.757897    -1.1408868     -6.4515824     -5.1825223      0.3880705     2.5104828     -1.8647186      1.7398003     -0.53895247    -3.8964303     -4.1509137     -3.1393435     -2.174281    -6.1708093     -5.2546153     -2.1971817     -4.55695    -4.3245444     -1.6113325     -4.6183186     -2.4085505    -3.1237144     -8.3430395      1.2164363     -3.4950488    -2.4105551     -3.26954       -3.483475      -3.6448991    -6.45342       -4.3655534     -3.9982698      2.0058196    13.91262     ]
  [  2.5283318     -1.4483672      0.9969271      0.7170124     4.1993585     -5.9225745     -1.3270315      1.2754217     0.6596287      1.3184649     -3.2381012     16.223343    -2.6598966     -1.6049436     -5.1619163     -5.2185836    -3.4646883      0.37716112    -1.4162335     -3.7551687     6.011435      -6.2358327     -1.0053082     -5.046207    -4.0837035      0.4770194      1.1101766     -0.33754197     1.6581774     -4.2621255      1.5940342      1.3807868    -2.2744715     -0.29614684    -2.8848875     -2.2694578    -8.568389     -10.925359      -0.16693757    -1.9699303    -5.057368      -3.8518627     -1.813983     -14.393661    -8.807828     -10.923024      -8.132841       6.037188     6.71938     ]
  [ -1.0551867     -1.7578293      1.9037585      3.2873793     2.0240114     -2.354026       0.60487497    -0.18619181    -2.147204       0.6680657     -5.2943177     10.29514    -3.7262926     -2.830817      -2.7276952     -5.4776435    -2.9794304     -3.8625076     -1.3735079     -2.5151794     2.8896475     -4.4512296     -2.0915463     -1.2939028    -3.104559      -2.2537181     -4.120955      -4.342249    -1.8565747     -6.2458816     -2.3996937     -1.9764471    -6.0649962     -2.6825225     -5.5547967     -4.4913697    -5.119028      -4.1911855      2.1648426      0.5508409     5.076616       1.6188253     -3.582057      -7.621736    -1.5033997     -2.183586       1.0535034      9.071255    11.899856    ]
  [ -5.2529254     -6.6716137     -3.1146243     -6.264843    -2.824476       5.0508304     -1.5491694     -1.2883891     0.74578935    -7.33851       -3.1347349     -2.9942334     0.5507162     -1.6148804     -4.938992       0.6466265    -2.2037792     -1.9882045     -6.203813       4.076163    -4.691016       1.2091874     -1.0557848     -4.588415    -1.2097976     -3.7823641     -4.6124034     -2.0866807    -3.623191      -5.36186       -4.4979167     -4.4606586    -5.770378      -1.2358248     -6.613919      -3.8514888    -6.235285      -5.905029      -1.0715307      2.8696413    -0.47416314     2.7852128     -4.025336      -4.1802793     0.25927126    -1.3094192      3.6837552     13.21021    11.347459    ]
  [ -5.057721      -5.343788      -1.7458328     -6.3566365    -2.9424264      2.2776768     -3.4749358     -5.947929     3.3519404     -3.874953      -6.0880322     -6.619028    -0.37194625    -1.7473186     -5.295511      -3.2047918    -1.077995      -7.218947      -4.7407937      3.0634851    -6.251387       1.4197563      0.4252913     -5.691605    -2.564915      -6.166654      -5.7835813     -1.8982929    -4.4162564     -3.5899343     -4.082336      -4.0357556    -6.603014      -3.4210358     -7.8280125     -1.4068938    -5.7733307     -8.0943    -2.8861597     -2.887181    -3.1830013     -1.4008173     -2.458579      -2.2794507    -2.2364883     -2.1403112      2.0037267      9.625611    12.308739    ]
  [ -4.736945     -10.628989      -4.470187      -5.965631    -4.763827      -0.7323       -12.857819       0.12708224     4.8935037     -6.2190022      0.14463969    -3.6041832     6.298675       7.4380403     -8.638773      -5.8449683    -2.175786      -2.8586502     -7.0307355      3.7856443    -7.0863433     -3.1873302      3.9701254      0.7573487     1.4138317     -9.364082     -10.078433      -5.241612    -5.444578      -6.0157566     -4.574983      -9.558782   -12.992415      -2.7820683     -9.652053      -2.7950761    -5.322698     -10.596647      -0.91065645    -5.9889627    -0.9559841     -6.9453692      4.51732       -6.399874    -8.571931      -5.1669536     -4.506823       3.0171888    22.158484    ]
  [ -3.068115      -4.752106      -3.8195612     -9.741685    -8.325681       8.063115      -7.9095597     13.477923     3.2089014    -10.606659       3.0653007     -2.3270218    21.029633       4.2431703     -5.482428       7.7515645     5.5879655      2.1668143     -5.791489      -0.39452899    -9.12094    6.6312127     12.389896       5.121841    11.055828      -4.6672044     -3.212209       2.9474885    -1.384693      -1.3363131     -1.3095058     -2.4004366    -4.466605       4.201877      -2.345684       0.7684905    -1.7537786     -8.601547      -2.332861      -2.8643725    -5.8592925      4.338715      -3.1820097     -2.8485777    -7.5072083     -4.256681      -2.5743508      0.94620275     7.3088403   ]
  [ -5.452369      -9.016264      -5.144456      -4.3855796    -7.7754283      1.135269      -6.0672054     -0.46107984    -1.5757593    -10.944435      -5.541817      -3.7400455     1.863794      -4.2366767     -6.463822      -1.712952    -0.47423482    -5.9268956    -11.652019      -1.4437933   -12.260867       0.07316127     0.79780954    -7.9282737     0.9615293     -5.531859      -8.971187      -6.121879    -5.8926487     -8.665367      -7.853302      -6.535997    -8.472007      -1.7106935     -9.621098      -3.748615    -9.184453     -11.467549      -1.8488725      2.7637093     0.13214706    12.264789      -1.925021      -4.1397038     0.675782       0.8341355      4.790847      15.223495    16.989325    ]
  [ -3.9985054     -9.17712       -9.745225      -9.341779    -4.371359      -3.9573042     -5.219108     -10.031667    -0.4832547     -7.221607      -9.378301      -3.553962    -4.277628      -8.165889      -6.766566      -7.317974    -6.7054176     -8.275714      -8.473683      -2.6473777    -9.137348      -4.5135856     -7.3449397     -4.220116    -4.296596      -0.122100346   -8.692269       9.825402     0.2553134     -1.4249631      1.4904976     -3.87309    -6.7046905      4.780445      -8.814603      -3.5223646    -8.859568     -13.593255      -7.687883       1.6292764     2.5215695     10.300719      -0.8014014     -8.760519     0.9533107     -2.471599      -0.55962145    15.309047     8.776088    ]
  [  2.1049914     -5.7175593     -0.6238275     -1.5772029    -2.3334796     -7.376515      -5.821173      -4.5206504     5.1160502      0.7101815     -2.4477665      1.0354464    -3.0778773     -5.6364365     -3.1852434     -6.0968738    -0.25753418    -4.420667      -5.6371856      2.2084491    -6.0431843     -1.6050267     -3.8200142     -0.9649778    -1.0719372      3.1703932      0.28604648    19.212442     5.1282506      1.6608907      3.9577866     -1.4500607    -7.6976585      6.7093034     -5.434231      -0.1969173    -1.6897439    -11.350258      -5.0953856     -2.5845845    -8.346431      -5.030808      -7.1316266    -10.417641    -9.598651     -12.076622     -15.840962      -2.767027     5.2507353   ]
  [ -1.6916462     -6.835287      -1.2959373     -1.9050026    -6.942196      -3.4665506     -4.852651      -3.9581516     1.3320965     -3.2232249      0.0419402     -0.6517505    -3.0223713      0.40320182    -3.8511922     -5.849378    -3.6755798     -4.371869      -4.9620113     -1.1411376    -1.0673978     -3.7844536     -1.251507      -5.0279365    -2.329897      -5.9839554      2.9948866      1.7984604    -2.9251158     -2.347848      -0.07170879    -2.4061537    -1.4042406     -2.319747      -4.6162496     -1.4313077    -4.4996104     -6.91234       -0.17195721    -6.1135383    -4.90153       -7.101444      -5.3525157     -5.6080756    -8.066487      -7.533741      -8.561157      -0.61673695    11.969102    ]
  [ -5.2910733     -4.0735116      3.8942814      4.9986653    -8.251605      -5.863548       0.52648324    -2.2165954    -6.2707744      4.5292373     -7.903667      -1.6777164    -7.690946      -3.0448997      9.52889       -3.925293     3.7865422     -6.1437564      1.8726383     -5.674963     3.302004      -3.169571      -5.190231      -7.159308    -5.56988       -6.0096536     14.196355      -2.219622    -3.208381       2.9780896      0.40442243    -1.306855    -1.3609582     -1.6217264      1.4096924      2.9067333   -10.75253       -1.7663544      3.9251118     -6.1464143   -13.524259      -3.199681       0.40105966   -12.946118   -11.353162     -12.651736     -14.381966      -2.9572937     6.5882106   ]
  [ -1.9417683     -5.0573096     -2.8481205     -2.6008158    -3.7663803     -5.171085      -4.253186      -6.007723    -0.06816677     2.1923892     -4.1221375     -2.1063364    -4.822325      -1.5166817      0.07642153    -5.5134835     0.9086635     -5.2698345     -3.3004758     -1.0602385    -1.2910267     -1.3988553     -1.7253238     -3.6106098    -3.3936682     -3.8622196      3.0371997     -0.35850498    -5.599482      -3.3486063     -2.944565      -3.8021555    -3.807739      -1.49082       -2.3763907     -2.1279447    -5.170482      -5.828091      -0.5425779     -3.1264536    -4.5475307     -1.6777412     -4.526622      -5.372235    -7.2601147     -5.48196       -6.54913       -1.120478    12.390136    ]
  [ -3.461581      -1.4558958      6.1289496      2.9735203    -1.2450281     -4.602448      -1.9891156     -6.117136    -5.5234065     -2.696553      -3.586568       2.8084233    -7.3573537     -4.507172       5.5286765     -2.4690719     2.523189      -2.8085434     -1.6559683     -1.8171147     2.1076992     -5.626428      -7.231596      -6.0143523    -6.9726806     -0.8886002     13.542512      -1.3580791     0.6832211      2.2281325      0.20517886     0.4207892     0.1542706      0.22497724     2.903372      -0.43212676    -9.586123      -6.539781       0.26695496    -8.207171   -15.066978      -5.713083      -2.879772     -16.250275   -12.022546     -15.688462     -14.957932      -2.622998     5.1257606   ]
  [ -5.2359405     -6.4311886      3.7954795     -0.6747386    -3.9157393     -4.123837      -3.995203      -6.349108    -3.793074      -0.80095726    -1.330827      -2.0078313    -5.1554894     -2.8631523     -0.881418      -5.6142144    -1.8561249     -6.5457616     -4.5799966     -2.044014     0.47274694    -1.1704346     -3.5675278     -4.5367837    -5.979168      -5.4071426      6.3918777     -1.1991844    -2.0291529     -0.08346957    -1.2887247     -3.2507048    -1.9896507     -0.8941142     -0.2793278     -3.2223158    -5.5826225     -4.921161       0.6414426     -7.240561    -9.987512      -5.0585003     -6.553722      -7.946823    -8.550385      -7.669768      -9.521777      -3.718647    13.088218    ]
  [ -6.0787616     -2.760232      -1.467815       2.1198342    -8.399127      -8.965743      -1.4192119     -4.3845778    -8.508703      -0.2962972     -7.1257405     -3.9597538    -7.555639      -3.2412634      4.911804      -7.2009654     1.1253124     -6.595501      -3.956956      -5.8060346     2.4504921     -3.4591324     -5.757239     -10.887218    -9.258279      -9.541945      12.070434      -1.5752869    -6.057066       2.3558514     -3.168074      -2.4653132     0.12063774    -2.8162138      4.471817      -0.35249588   -14.35635       -4.5517406      0.36203933    -8.030429   -15.201206      -6.287722       0.23622651   -19.051283   -11.752037     -14.967655     -13.759575      -3.3683908    10.117752    ]
  [ -7.079468      -5.265597      -1.5848751      2.253567    -6.46945       -8.430444      -3.5897791     -7.8991075    -5.6643214      2.3023212     -7.853886      -3.5041678   -12.051305     -10.392461       2.6387234     -5.6902485    -0.25494644    -7.3672867     -6.844403      -7.0112057     0.7349677     -3.6644032     -5.8336225     -6.475676    -8.460027      -3.5292912     13.694934       2.082901    -2.1121929      2.6222725     -6.9787374     -1.9552851    -2.3152606      1.9507776      5.016398      -0.16578133   -10.859069      -5.3187003      0.8972644     -5.7399955   -14.465164      -3.2254312      1.2975389    -15.831334   -14.408114     -14.99931      -14.778538      -1.4908476    11.922107    ]
  [ -1.9436159     -4.575247      -6.390955      -4.9047637    -3.2908394     -3.1129427     -2.3592062     -1.394528    -2.3547149     -1.6598221     -2.1417007     -3.1081944    -2.5159578     -7.691215      -4.6543746     -4.771032    -2.7071314     -6.7351565     -4.7741923     -3.364289    -7.471546      -2.3670242     -7.543904      -5.047063    -4.729469      -5.9341073      0.3747803     -1.0018672     0.9036009      1.5984081     -1.3429843     -0.2840887     1.367341       1.3728013     -1.4689537     -1.5738052    -9.112517      -9.113147      -3.9519968     -4.039954    -4.3511705     -7.818344       0.18420011   -10.240898    -8.708661      -9.73697       -9.248626      -3.1827362    14.422031    ]
  [ -6.3566413     -8.544102     -10.048785      -5.773206    -3.3318303     -2.4811735     -3.6157846     -4.06117   -11.2877655     -3.158837      -7.167846      -9.7644825   -10.089507     -10.784669      -9.1176    -7.5642204    -4.9335723     -7.0899386     -6.513907      -1.8153943    -7.955276      -3.2648313     -9.505028      -9.440993    -4.5477047    -10.648444      -0.6833103     -1.6586121    -3.2512772     -2.2827086     -4.558927       0.26295188    -0.07339359     1.532421      -0.18356426    -4.358731   -11.891158      -8.6237    -7.578995      -6.1212106   -13.254722     -15.914986     -11.113473     -18.317835   -15.800079     -17.134977     -19.690008      -7.6697803    13.230232    ]
]]

Output: [[ 20 11 47 12 47 27 26 26 26]]

Java (tested on Android, compiled TF2.3, see above)

The same tensor used in java (shape=(1, 24, 49), dtype=float32) against the decoder.tflite model:

final float[][][] logits_test= {{
        { -1.1646128f,-3.7951221f,-1.0731119f,-5.230322f,-4.3759046f,-1.1051129f,-5.9621816f,-2.1139586f,-1.6347717f,-3.0709565f,0.25088528f,-4.5464454f,0.9719744f,-2.6028876f,-5.2125697f,-4.693067f,-3.4992895f,-6.196344f,-1.9408542f,-1.8609589f,-5.123465f,-2.1778982f,-0.3016574f,-1.4162496f,-0.05596298f,-3.3783443f,-4.0272593f,-3.7445364f,-0.0028205316f, -0.8726251f,-2.6476762f,-2.7670584f,-3.531002f,-2.86586f, -3.0021574f,1.9833964f,-6.5366592f,-4.3795114f,-9.089881f,-2.9438267f,-2.824938f,-8.183831f,-5.9174848f,-15.839222f,-8.734572f,-10.726117f,-9.316691f, 4.295628f,18.199356f},
        { -0.031096319f,-3.871109f,-1.1181607f,-2.0011232f,-4.7141924f,-1.2818102f,-4.978454f, 2.0263755f,-0.21877344f,-0.46911952f,1.3215663f,-2.7769063f,3.4695244f,-1.7167692f,-4.468163f,-3.00177f,-3.4645154f,-4.2073197f,-5.397524f,-0.36775938f,-4.821177f,-1.638662f, 0.23415852f,-1.3846282f,-2.6762388f,-4.1896615f,-1.411914f,-2.8303812f,1.251152f, 0.5686881f,-0.6898544f,-2.794163f,-4.0943656f,-2.028222f,-4.0183196f,2.4679868f,-2.5596936f,-1.7351736f,-5.4891076f,-1.3824191f,-2.1094246f,-2.8548317f,-3.896057f,-13.179549f,-8.732274f,-8.050248f,-7.7822146f,1.5458045f,20.359257f},
        {  1.2163008f,-2.6954525f,-0.86427027f,0.6024355f,-6.1996074f,-3.0337527f,-3.3046398f,2.9629385f,3.3836906f,0.6956072f,-0.5831372f,0.26549777f,2.1988766f,0.034438375f,-1.2926706f,-3.415465f,-1.8027607f,-4.706817f,-2.7042725f,1.7454389f,-1.63372f, -2.0432458f,0.5463361f,-2.4805515f,-3.2112253f,-3.8260605f,-2.330295f, 0.48245263f,-2.5352879f,-1.9981833f,-3.6866705f,-4.316192f,-4.7724094f,-3.8186944f,-6.9987373f,0.83749133f,-5.358316f,-3.382599f,-3.0282784f,-1.8950666f,-4.312699f,-0.3736072f,-5.263495f,-11.096023f,-10.782363f,-8.377029f,-9.81446f, -0.5631078f,18.654766f},
        {  1.6706834f,-2.135751f,-2.6569047f,1.4258738f,-3.101607f,-7.347342f,-6.336166f,-0.92469734f,3.8745248f,-0.68873376f,-2.5481994f,3.0339756f,0.019852579f,2.4946487f,-3.264964f,-9.122855f,-0.5293837f,-3.387656f,-6.479887f,-0.41217116f,2.1036355f,-5.3812556f,-4.8552337f,-4.6979804f,-6.1752295f,-3.2327073f,-3.25391f, -1.0128698f,-4.135406f,-8.941207f,-3.8629827f,-5.694706f,-7.9600415f,-6.6381497f,-7.7798233f,-4.398782f,-5.243107f,-6.0830593f,3.9232616f,-4.3167377f,-3.767523f,-3.2243702f,-5.2422233f,-9.081962f,-9.653151f,-6.1841607f,-6.414804f, 3.442686f,16.106243f},
        {  2.5365763f,-0.3145837f,6.921036f, 5.1193705f,1.4797157f,-8.922007f, 2.5846255f,1.3787552f,3.09406f,  9.555295f,-2.7645082f,15.209727f,-2.015432f,-3.7025976f,4.959807f,-5.207284f,0.76611304f,-3.6603796f,3.0620315f,-6.1943145f,18.713396f,-1.9181551f,-0.14312221f,-3.73462f,-5.586571f, 4.035087f, 6.6243644f,-4.5170846f,-2.1310537f,-4.0330253f,3.1677713f,-0.8995264f,0.41301596f,-2.8552415f,-1.0611678f,-2.8348706f,-7.8290887f,-1.8352652f,7.9356976f,-6.084311f,-6.470459f,-0.59961814f,-2.9941504f,-5.9037833f,-8.757953f,-8.05204f, -7.22634f, -2.3976681f,5.6136956f},
        {  0.86832124f,-4.314832f,-1.1376096f,-1.2795423f,0.89594346f,-3.2714832f,-4.813009f,-3.6954434f,6.292471f, 1.9540067f,-1.269824f, 3.7818973f,1.2630774f,2.311032f,-3.6972969f,-8.757897f,-1.1408868f,-6.4515824f,-5.1825223f,0.3880705f,2.5104828f,-1.8647186f,1.7398003f,-0.53895247f,-3.8964303f,-4.1509137f,-3.1393435f,-2.174281f,-6.1708093f,-5.2546153f,-2.1971817f,-4.55695f,-4.3245444f,-1.6113325f,-4.6183186f,-2.4085505f,-3.1237144f,-8.3430395f,1.2164363f,-3.4950488f,-2.4105551f,-3.26954f, -3.483475f,-3.6448991f,-6.45342f, -4.3655534f,-3.9982698f,2.0058196f,13.91262f},
        {  2.5283318f,-1.4483672f,0.9969271f,0.7170124f,4.1993585f,-5.9225745f,-1.3270315f,1.2754217f,0.6596287f,1.3184649f,-3.2381012f,16.223343f,-2.6598966f,-1.6049436f,-5.1619163f,-5.2185836f,-3.4646883f,0.37716112f,-1.4162335f,-3.7551687f,6.011435f,-6.2358327f,-1.0053082f,-5.046207f,-4.0837035f,0.4770194f,1.1101766f,-0.33754197f,1.6581774f,-4.2621255f,1.5940342f,1.3807868f,-2.2744715f,-0.29614684f,-2.8848875f,-2.2694578f,-8.568389f,-10.925359f,-0.16693757f,-1.9699303f,-5.057368f,-3.8518627f,-1.813983f,-14.393661f,-8.807828f,-10.923024f,-8.132841f, 6.037188f,6.71938f},
        { -1.0551867f,-1.7578293f,1.9037585f,3.2873793f,2.0240114f,-2.354026f, 0.60487497f,-0.18619181f,-2.147204f, 0.6680657f,-5.2943177f,10.29514f,-3.7262926f,-2.830817f,-2.7276952f,-5.4776435f,-2.9794304f,-3.8625076f,-1.3735079f,-2.5151794f,2.8896475f,-4.4512296f,-2.0915463f,-1.2939028f,-3.104559f,-2.2537181f,-4.120955f,-4.342249f,-1.8565747f,-6.2458816f,-2.3996937f,-1.9764471f,-6.0649962f,-2.6825225f,-5.5547967f,-4.4913697f,-5.119028f,-4.1911855f,2.1648426f,0.5508409f,5.076616f, 1.6188253f,-3.582057f,-7.621736f,-1.5033997f,-2.183586f, 1.0535034f,9.071255f,11.899856f},
        { -5.2529254f,-6.6716137f,-3.1146243f,-6.264843f,-2.824476f, 5.0508304f,-1.5491694f,-1.2883891f,0.74578935f,-7.33851f, -3.1347349f,-2.9942334f,0.5507162f,-1.6148804f,-4.938992f, 0.6466265f,-2.2037792f,-1.9882045f,-6.203813f, 4.076163f,-4.691016f, 1.2091874f,-1.0557848f,-4.588415f,-1.2097976f,-3.7823641f,-4.6124034f,-2.0866807f,-3.623191f,-5.36186f, -4.4979167f,-4.4606586f,-5.770378f,-1.2358248f,-6.613919f,-3.8514888f,-6.235285f,-5.905029f,-1.0715307f,2.8696413f,-0.47416314f,2.7852128f,-4.025336f,-4.1802793f,0.25927126f,-1.3094192f,3.6837552f,13.21021f,11.347459f},
        { -5.057721f,-5.343788f,-1.7458328f,-6.3566365f,-2.9424264f,2.2776768f,-3.4749358f,-5.947929f,3.3519404f,-3.874953f,-6.0880322f,-6.619028f,-0.37194625f,-1.7473186f,-5.295511f,-3.2047918f,-1.077995f,-7.218947f,-4.7407937f,3.0634851f,-6.251387f, 1.4197563f,0.4252913f,-5.691605f,-2.564915f,-6.166654f,-5.7835813f,-1.8982929f,-4.4162564f,-3.5899343f,-4.082336f,-4.0357556f,-6.603014f,-3.4210358f,-7.8280125f,-1.4068938f,-5.7733307f,-8.0943f,  -2.8861597f,-2.887181f,-3.1830013f,-1.4008173f,-2.458579f,-2.2794507f,-2.2364883f,-2.1403112f,2.0037267f,9.625611f,12.308739f},
        { -4.736945f,-10.628989f,-4.470187f,-5.965631f,-4.763827f,-0.7323f, -12.857819f, 0.12708224f,4.8935037f,-6.2190022f,0.14463969f,-3.6041832f,6.298675f, 7.4380403f,-8.638773f,-5.8449683f,-2.175786f,-2.8586502f,-7.0307355f,3.7856443f,-7.0863433f,-3.1873302f,3.9701254f,0.7573487f,1.4138317f,-9.364082f,-10.078433f,-5.241612f,-5.444578f,-6.0157566f,-4.574983f,-9.558782f,-12.992415f,-2.7820683f,-9.652053f,-2.7950761f,-5.322698f,-10.596647f,-0.91065645f,-5.9889627f,-0.9559841f,-6.9453692f,4.51732f, -6.399874f,-8.571931f,-5.1669536f,-4.506823f, 3.0171888f,22.158484f},
        { -3.068115f,-4.752106f,-3.8195612f,-9.741685f,-8.325681f, 8.063115f,-7.9095597f,13.477923f,3.2089014f,-10.606659f, 3.0653007f,-2.3270218f,21.029633f, 4.2431703f,-5.482428f, 7.7515645f,5.5879655f,2.1668143f,-5.791489f,-0.39452899f,-9.12094f,  6.6312127f,12.389896f, 5.121841f,11.055828f,-4.6672044f,-3.212209f, 2.9474885f,-1.384693f,-1.3363131f,-1.3095058f,-2.4004366f,-4.466605f, 4.201877f,-2.345684f, 0.7684905f,-1.7537786f,-8.601547f,-2.332861f,-2.8643725f,-5.8592925f,4.338715f,-3.1820097f,-2.8485777f,-7.5072083f,-4.256681f,-2.5743508f,0.94620275f,7.3088403f},
        { -5.452369f,-9.016264f,-5.144456f,-4.3855796f,-7.7754283f,1.135269f,-6.0672054f,-0.46107984f,-1.5757593f,-10.944435f,-5.541817f,-3.7400455f,1.863794f,-4.2366767f,-6.463822f,-1.712952f,-0.47423482f,-5.9268956f,-11.652019f,-1.4437933f,-12.260867f, 0.07316127f,0.79780954f,-7.9282737f,0.9615293f,-5.531859f,-8.971187f,-6.121879f,-5.8926487f,-8.665367f,-7.853302f,-6.535997f,-8.472007f,-1.7106935f,-9.621098f,-3.748615f,-9.184453f,-11.467549f,-1.8488725f,2.7637093f,0.13214706f,12.264789f,-1.925021f,-4.1397038f,0.675782f, 0.8341355f,4.790847f,15.223495f,16.989325f},
        { -3.9985054f,-9.17712f, -9.745225f,-9.341779f,-4.371359f,-3.9573042f,-5.219108f,-10.031667f,-0.4832547f,-7.221607f,-9.378301f,-3.553962f,-4.277628f,-8.165889f,-6.766566f,-7.317974f,-6.7054176f,-8.275714f,-8.473683f,-2.6473777f,-9.137348f,-4.5135856f,-7.3449397f,-4.220116f,-4.296596f,-0.122100346f,-8.692269f, 9.825402f,0.2553134f,-1.4249631f,1.4904976f,-3.87309f,-6.7046905f,4.780445f,-8.814603f,-3.5223646f,-8.859568f,-13.593255f,-7.687883f, 1.6292764f,2.5215695f,10.300719f,-0.8014014f,-8.760519f,0.9533107f,-2.471599f,-0.55962145f,15.309047f,8.776088f},
        {  2.1049914f,-5.7175593f,-0.6238275f,-1.5772029f,-2.3334796f,-7.376515f,-5.821173f,-4.5206504f,5.1160502f,0.7101815f,-2.4477665f,1.0354464f,-3.0778773f,-5.6364365f,-3.1852434f,-6.0968738f,-0.25753418f,-4.420667f,-5.6371856f,2.2084491f,-6.0431843f,-1.6050267f,-3.8200142f,-0.9649778f,-1.0719372f,3.1703932f,0.28604648f,19.212442f,5.1282506f,1.6608907f,3.9577866f,-1.4500607f,-7.6976585f,6.7093034f,-5.434231f,-0.1969173f,-1.6897439f,-11.350258f,-5.0953856f,-2.5845845f,-8.346431f,-5.030808f,-7.1316266f,-10.417641f,-9.598651f,-12.076622f,-15.840962f,-2.767027f,5.2507353f},
        { -1.6916462f,-6.835287f,-1.2959373f,-1.9050026f,-6.942196f,-3.4665506f,-4.852651f,-3.9581516f,1.3320965f,-3.2232249f,0.0419402f,-0.6517505f,-3.0223713f,0.40320182f,-3.8511922f,-5.849378f,-3.6755798f,-4.371869f,-4.9620113f,-1.1411376f,-1.0673978f,-3.7844536f,-1.251507f,-5.0279365f,-2.329897f,-5.9839554f,2.9948866f,1.7984604f,-2.9251158f,-2.347848f,-0.07170879f,-2.4061537f,-1.4042406f,-2.319747f,-4.6162496f,-1.4313077f,-4.4996104f,-6.91234f, -0.17195721f,-6.1135383f,-4.90153f, -7.101444f,-5.3525157f,-5.6080756f,-8.066487f,-7.533741f,-8.561157f,-0.61673695f,11.969102f},
        { -5.2910733f,-4.0735116f,3.8942814f,4.9986653f,-8.251605f,-5.863548f, 0.52648324f,-2.2165954f,-6.2707744f,4.5292373f,-7.903667f,-1.6777164f,-7.690946f,-3.0448997f,9.52889f, -3.925293f,3.7865422f,-6.1437564f,1.8726383f,-5.674963f,3.302004f,-3.169571f,-5.190231f,-7.159308f,-5.56988f, -6.0096536f,14.196355f,-2.219622f,-3.208381f, 2.9780896f,0.40442243f,-1.306855f,-1.3609582f,-1.6217264f,1.4096924f,2.9067333f,-10.75253f, -1.7663544f,3.9251118f,-6.1464143f,-13.524259f,-3.199681f, 0.40105966f,-12.946118f,-11.353162f,-12.651736f,-14.381966f,-2.9572937f,6.5882106f},
        { -1.9417683f,-5.0573096f,-2.8481205f,-2.6008158f,-3.7663803f,-5.171085f,-4.253186f,-6.007723f,-0.06816677f,2.1923892f,-4.1221375f,-2.1063364f,-4.822325f,-1.5166817f,0.07642153f,-5.5134835f,0.9086635f,-5.2698345f,-3.3004758f,-1.0602385f,-1.2910267f,-1.3988553f,-1.7253238f,-3.6106098f,-3.3936682f,-3.8622196f,3.0371997f,-0.35850498f,-5.599482f,-3.3486063f,-2.944565f,-3.8021555f,-3.807739f,-1.49082f, -2.3763907f,-2.1279447f,-5.170482f,-5.828091f,-0.5425779f,-3.1264536f,-4.5475307f,-1.6777412f,-4.526622f,-5.372235f,-7.2601147f,-5.48196f, -6.54913f, -1.120478f,12.390136f},
        { -3.461581f,-1.4558958f,6.1289496f,2.9735203f,-1.2450281f,-4.602448f,-1.9891156f,-6.117136f,-5.5234065f,-2.696553f,-3.586568f, 2.8084233f,-7.3573537f,-4.507172f, 5.5286765f,-2.4690719f,2.523189f,-2.8085434f,-1.6559683f,-1.8171147f,2.1076992f,-5.626428f,-7.231596f,-6.0143523f,-6.9726806f,-0.8886002f,13.542512f,-1.3580791f,0.6832211f,2.2281325f,0.20517886f,0.4207892f,0.1542706f,0.22497724f,2.903372f,-0.43212676f,-9.586123f,-6.539781f, 0.26695496f,-8.207171f,-15.066978f,-5.713083f,-2.879772f,-16.250275f,-12.022546f,-15.688462f,-14.957932f,-2.622998f,5.1257606f},
        { -5.2359405f,-6.4311886f,3.7954795f,-0.6747386f,-3.9157393f,-4.123837f,-3.995203f,-6.349108f,-3.793074f,-0.80095726f,-1.330827f,-2.0078313f,-5.1554894f,-2.8631523f,-0.881418f,-5.6142144f,-1.8561249f,-6.5457616f,-4.5799966f,-2.044014f,0.47274694f,-1.1704346f,-3.5675278f,-4.5367837f,-5.979168f,-5.4071426f,6.3918777f,-1.1991844f,-2.0291529f,-0.08346957f,-1.2887247f,-3.2507048f,-1.9896507f,-0.8941142f,-0.2793278f,-3.2223158f,-5.5826225f,-4.921161f, 0.6414426f,-7.240561f,-9.987512f,-5.0585003f,-6.553722f,-7.946823f,-8.550385f,-7.669768f,-9.521777f,-3.718647f,13.088218f},
        { -6.0787616f,-2.760232f,-1.467815f, 2.1198342f,-8.399127f,-8.965743f,-1.4192119f,-4.3845778f,-8.508703f,-0.2962972f,-7.1257405f,-3.9597538f,-7.555639f,-3.2412634f,4.911804f,-7.2009654f,1.1253124f,-6.595501f,-3.956956f,-5.8060346f,2.4504921f,-3.4591324f,-5.757239f,-10.887218f,-9.258279f,-9.541945f,12.070434f,-1.5752869f,-6.057066f, 2.3558514f,-3.168074f,-2.4653132f,0.12063774f,-2.8162138f,4.471817f,-0.35249588f,-14.35635f, -4.5517406f,0.36203933f,-8.030429f,-15.201206f,-6.287722f, 0.23622651f,-19.051283f,-11.752037f,-14.967655f,-13.759575f,-3.3683908f,10.117752f},
        { -7.079468f,-5.265597f,-1.5848751f,2.253567f,-6.46945f, -8.430444f,-3.5897791f,-7.8991075f,-5.6643214f,2.3023212f,-7.853886f,-3.5041678f,-12.051305f,-10.392461f, 2.6387234f,-5.6902485f,-0.25494644f,-7.3672867f,-6.844403f,-7.0112057f,0.7349677f,-3.6644032f,-5.8336225f,-6.475676f,-8.460027f,-3.5292912f,13.694934f, 2.082901f,-2.1121929f,2.6222725f,-6.9787374f,-1.9552851f,-2.3152606f,1.9507776f,5.016398f,-0.16578133f,-10.859069f,-5.3187003f,0.8972644f,-5.7399955f,-14.465164f,-3.2254312f,1.2975389f,-15.831334f,-14.408114f,-14.99931f,-14.778538f,-1.4908476f,11.922107f},
        { -1.9436159f,-4.575247f,-6.390955f,-4.9047637f,-3.2908394f,-3.1129427f,-2.3592062f,-1.394528f,-2.3547149f,-1.6598221f,-2.1417007f,-3.1081944f,-2.5159578f,-7.691215f,-4.6543746f,-4.771032f,-2.7071314f,-6.7351565f,-4.7741923f,-3.364289f,-7.471546f,-2.3670242f,-7.543904f,-5.047063f,-4.729469f,-5.9341073f,0.3747803f,-1.0018672f,0.9036009f,1.5984081f,-1.3429843f,-0.2840887f,1.367341f, 1.3728013f,-1.4689537f,-1.5738052f,-9.112517f,-9.113147f,-3.9519968f,-4.039954f,-4.3511705f,-7.818344f, 0.18420011f,-10.240898f,-8.708661f,-9.73697f, -9.248626f,-3.1827362f,14.422031f},
        { -6.3566413f,-8.544102f,-10.048785f,-5.773206f,-3.3318303f,-2.4811735f,-3.6157846f,-4.06117f,-11.2877655f,-3.158837f,-7.167846f,-9.7644825f,-10.089507f,-10.784669f,-9.1176f,  -7.5642204f,-4.9335723f,-7.0899386f,-6.513907f,-1.8153943f,-7.955276f,-3.2648313f,-9.505028f,-9.440993f,-4.5477047f,-10.648444f,-0.6833103f,-1.6586121f,-3.2512772f,-2.2827086f,-4.558927f, 0.26295188f,-0.07339359f,1.532421f,-0.18356426f,-4.358731f,-11.891158f,-8.6237f,  -7.578995f,-6.1212106f,-13.254722f,-15.914986f,-11.113473f,-18.317835f,-15.800079f,-17.134977f,-19.690008f,-7.6697803f,13.230232f}
        }};

Method in java (e.g. length = 20, has to be larger than expected dynamic results):

public static IntBuffer[] run(Interpreter interpreter, int length, float[][][] outputLogits){
    try {
        Object[] inputs = {outputLogits, new int[]{1}}; // batch size 1
        Map<Integer, Object> outputs = new HashMap<>();
        IntBuffer[] results = new IntBuffer[3];

        for (int i = 0; i < 3; i++){
        ByteBuffer buffer = ByteBuffer.allocateDirect(length * 4);//int32
        buffer.order(ByteOrder.nativeOrder());
        IntBuffer output = buffer.asIntBuffer();

        results[i] = output;
        outputs.put(i, output);
        }
        interpreter.runForMultipleInputsOutputs(inputs, outputs);
        return results;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

Output: [20, 11, 47, 12, 47, 27, 26, 26, 26, 0]

cefaci

comment created time in 2 months

issue commenttensorflow/tensorflow

TFLite: C++/Java: experimental kernel ctc_beam_search_decoder returns always buffer length=length+1

Mhhhh, maybe you are right, it could be from the logits too and then from java as I get the logits from encoder.tflite in java and pass them to the decoder.tflite, where I see the prescribed result

cefaci

comment created time in 2 months

issue commenttensorflow/tensorflow

TFLite: C++/Java: experimental kernel ctc_beam_search_decoder returns always buffer length=length+1

Thank you for your help!

  • "Have you tried with python tflite api?": As described, yes and works => If I use the concrete function directly in python it works as expected => If I use the concrete function exported as decoder.tflite and loaded directly in python it works as expected.

  • "Also, wonder if this only occurs with java usage?": This I can't say you for sure if the Tensor.java fills the bytes wrong, but I'm quite sure it is coming from the C++ experimental kernel, as from the return of my concrete function (above) dense_decoded I'll concat my probability in the end and the 0 zero value is then in between

    ...
    dense_decoded = tf.sparse.to_dense(decoded[0], default_value=-1)
    ...
    output = tf.concat([dense_decoded, probabilities_int, 1)

So the output dense_decoded is [11,11,4,7,8,0] with the added probability [11,11,4,7,8,0, 89] and the zero is befor which comes from tf.nn.ctc_beam_search_decoder or tf.sparse.to_dense.

In python the direct model with the concrete function (e.g. training with inference) or loaded as exported tflite works as expected.

cefaci

comment created time in 2 months

issue openedtensorflow/tensorflow

TFLite: C++/Java: experimental kernel ctc_beam_search_decoder returns always buffer length=length+1

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 20.04
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Pixel 2
  • TensorFlow installed from (source or binary): source
  • TensorFlow version: master
  • Python version: 3.8
  • Installed using virtualenv? pip? conda?: pip
  • Bazel version (if compiling from source): 3.1.0
  • GCC/Compiler version (if compiling from source): 9.3.0
  • CUDA/cuDNN version: -
  • GPU model and memory: -
  • NDK: android-ndk-r20

Describe the current behavior All returned Java IntBuffer (TFLite Android) from the concrete function ( decoder.tflite) have an extra added byte=0 in the end of the returned dense_decoded, e.g. [11,11,4,7,8,0]. => This happens only in TFLite with the tflite experimental kernel ctc_beam_search_decoder.cc returned from Java.

Describe the expected behavior The returned dense_decoded from the concrete function ( decoder.tflite) should be e.g. [11,11,4,7,8]. => If I use the concrete function directly in python it works as expected => If I use the concrete function exported as decoder.tflite and loaded directly in python it works as expected.

Fast fix As the 0 index is part of the trained characters I changed the Resize method in ctc_beam_search_decoder.cc:

- 108: output_shape_array->data[i++] = v;
+ 108: output_shape_array->data[i++] = -1;

Now the IntBuffer results have added the default value=100 from tf.sparse.to_dense in the concrete function instead of the 0 value which is out of the character indices space, e.g. [11,11,4,7,8,100]

Standalone code to reproduce the issue

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout -b master 6e9d916229b5aefbdcfd33cbc4b34c9f48b5e6e1
nano .tf_configure.bazelrc

Bazel config .tf_configure.bazelrc:

build --action_env PYTHON_BIN_PATH="/usr/bin/python"
build --action_env PYTHON_LIB_PATH="/usr/lib/python3/dist-packages"
build --python_path="/usr/bin/python"
build:xla --define with_xla_support=true
build:opt --copt=-march=native
build:opt --copt=-Wno-sign-compare
build:opt --host_copt=-march=native
build:opt --define with_default_optimizations=true
build --action_env ANDROID_NDK_HOME="CHANGE_TO_YOUR_ANDROID_NDK_HOME"
build --action_env ANDROID_NDK_API_LEVEL="21"
build --action_env ANDROID_BUILD_TOOLS_VERSION="28.0.0"
build --action_env ANDROID_SDK_API_LEVEL="23"
build --action_env ANDROID_SDK_HOME="CHANGE_TO_YOUR_ANDROID_SDK_HOME"
test --flaky_test_attempts=3
test --test_size_filters=small,medium
test --test_tag_filters=-benchmark-test,-no_oss,-oss_serial
test --build_tag_filters=-benchmark-test,-no_oss
test --test_tag_filters=-gpu
test --build_tag_filters=-gpu
build --action_env TF_CONFIGURE_IOS="0"

And compile with

bazel build --cxxopt='--std=c++14' -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a --config=monolithic \
  --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
  //tensorflow/lite/java:tensorflow-lite \
  //tensorflow/lite/java:tensorflow-lite-gpu \
  //tensorflow/lite/delegates/flex:delegate \
  //tensorflow/lite/experimental/kernels:ctc_beam_search_decoder_op \
  //tmp:tensorflow-lite-select-tf-ops

Concrete function exported to decoder.tflite:

@tf.function
def decode(logits, top_paths=3, beam_width=3):
    batch_size_current, timesteps, _ = tf.shape(input=logits)
    seq_len = tf.fill([batch_size_current], timesteps)
    logits = tf.transpose(a=logits, perm=(1, 0, 2))

    decoded, log_probabilities = tf.nn.ctc_beam_search_decoder(inputs=logits, top_paths=top_paths, beam_width=beam_width, sequence_length=seq_len)

    dense_decoded = tf.sparse.to_dense(decoded[0], default_value=100)

created time in 2 months

issue openedtensorflow/tensorflow

TFLite: TF2.3 error building tensorflow-lite and tensorflow-lite-select-tf-ops

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): 20.04
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Pixel 2
  • TensorFlow installed from (source or binary): source
  • TensorFlow version: master
  • Python version: 3.8
  • Installed using virtualenv? pip? conda?: pip
  • Bazel version (if compiling from source): 3.1.0
  • GCC/Compiler version (if compiling from source): 9.3.0
  • CUDA/cuDNN version: -
  • GPU model and memory: -
  • NDK: android-ndk-r20

Describe the problem Getting this error if building tensorflow-lite with tensorflow-lite-select-tf-ops:

ERROR: /home/stardata/projects/lpr-ai/downloads/tensorflow/tensorflow/lite/delegates/flex/BUILD:77:1: C++ compilation of rule '//tensorflow/lite/delegates/flex:delegate_only_runtime' failed (Exit 1)
tensorflow/lite/delegates/flex/delegate.cc:152:37: error: 'TF_AcquireFlexDelegate' has C-linkage specified, but returns user-defined type 'tflite::TfLiteDelegateUniquePtr' (aka 'unique_ptr<TfLiteDelegate, void (*)(TfLiteDelegate *)>') which is incompatible with C [-Werror,-Wreturn-type-c-linkage]
    tflite::TfLiteDelegateUniquePtr TF_AcquireFlexDelegate() {
                                    ^
1 error generated.
Target //tmp:tensorflow-lite-select-tf-ops failed to build

Provide the exact sequence of commands / steps that you executed before running into the problem

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout -b master 6e9d916229b5aefbdcfd33cbc4b34c9f48b5e6e1
nano .tf_configure.bazelrc
build --action_env PYTHON_BIN_PATH="/usr/bin/python"
build --action_env PYTHON_LIB_PATH="/usr/lib/python3/dist-packages"
build --python_path="/usr/bin/python"
build:xla --define with_xla_support=true
build:opt --copt=-march=native
build:opt --copt=-Wno-sign-compare
build:opt --host_copt=-march=native
build:opt --define with_default_optimizations=true
build --action_env ANDROID_NDK_HOME="CHANGE_TO_YOUR_ANDROID_NDK_HOME"
build --action_env ANDROID_NDK_API_LEVEL="21"
build --action_env ANDROID_BUILD_TOOLS_VERSION="28.0.0"
build --action_env ANDROID_SDK_API_LEVEL="23"
build --action_env ANDROID_SDK_HOME="CHANGE_TO_YOUR_ANDROID_SDK_HOME"
test --flaky_test_attempts=3
test --test_size_filters=small,medium
test --test_tag_filters=-benchmark-test,-no_oss,-oss_serial
test --build_tag_filters=-benchmark-test,-no_oss
test --test_tag_filters=-gpu
test --build_tag_filters=-gpu
build --action_env TF_CONFIGURE_IOS="0"

And compile with

bazel build --cxxopt='--std=c++14' -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a --config=monolithic \
  --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
  //tensorflow/lite/java:tensorflow-lite \
  //tensorflow/lite/java:tensorflow-lite-gpu \
  //tensorflow/lite/delegates/flex:delegate \
  //tensorflow/lite/experimental/kernels:ctc_beam_search_decoder_op \
  //tmp:tensorflow-lite-select-tf-ops

or

EXPORT_DIR=/home/${User}/output/tflite
./tensorflow/lite/tools/build_aar.sh \
  --input_models=$EXPORT_DIR/detect.tflite,$EXPORT_DIR/Decode.tflite,$EXPORT_DIR/Encoder.tflite \
  --target_archs=arm64-v8a,armeabi-v7a \
  --tflite_custom_ops_deps=//tensorflow/lite/experimental/kernels:ctc_beam_search_decoder_op

Fast fix I just comment the lines 152-154 in tensorflow/lite/delegates/flex/delegate.cc (https://github.com/tensorflow/tensorflow/commit/536f6be302d945513fedff57e65d89f6e0e026db#diff-5b63f45ccbd2b9d4aa2edaf64a92e14b) and it worked (tested on Pixel 2 XL with Android 11)

  //  tflite::TfLiteDelegateUniquePtr TF_AcquireFlexDelegate() {
//  return tflite::FlexDelegate::Create();
//}

created time in 2 months

issue commentcefaci/super-simple-pg-dao

why no helpers?

Yeah they are awesome, saw them(!!), but when I started the plugin the batch insert logic there weren't the helpers and I just wanted json inserts and I was using the old format, e.g.

return t.batch([             t.none('INSERT INTO Users(name, age) VALUES($1, $2)', ['John', 23]),            ...         ]);

When I started it years ago, I wanted something for my json data which sets only the columns needed for a transaction insert and doing "cascade" inserts with the returning foreign keys (where no batch is working, maybe it is misleading wording in my doc). The second case I use it for are the more complex reads https://github.com/cefaci/super-simple-pg-dao#query and in the beginning I didn't like any DAO libs I found.

Your pg-promise lib is awesome, love it!

vitaly-t

comment created time in 2 months

push eventcefaci/super-simple-pg-dao

cefaci

commit sha 931f11bfbc6f8c0c4d05a648a4a168b39a736afd

package.json update for npm

view details

push time in 2 months

create barnchcefaci/super-simple-pg-dao

branch : github

created branch time in 2 months

created repositorycefaci/super-simple-pg-dao

Simple Nodejs PG DAO

created time in 2 months

more