Skip to content

Instantly share code, notes, and snippets.

View miquelbeltran's full-sized avatar

Miguel Beltran miquelbeltran

View GitHub Profile
// Pass the input data, as an array, that contains a single float array, with a single value
// So in all [0][0] = 21, a 1x1 matrix in the form a Array of FloatArray
val inp = arrayOf(floatArrayOf(21f))
val inputs = FirebaseModelInputs.Builder().add(inp).build()
// Run the model
interpreter.run(inputs, dataOptions)
.continueWith { task ->
try {
// The output is also a Array of FloatArray
// Input is a 1x1 Tensor
val inputDims = intArrayOf(1, 1)
// Output is a 1x1 Tensor
val outputDims = intArrayOf(1, 1)
// Define the Input and Output dimensions and types
val dataOptions = FirebaseModelInputOutputOptions.Builder()
.setInputFormat(0, FirebaseModelDataType.FLOAT32, inputDims)
.setOutputFormat(0, FirebaseModelDataType.FLOAT32, outputDims)
.build()
# Original: https://stackoverflow.com/a/45466355/673294 user: jdehesa
def freeze_session(session, keep_var_names=None, output_names=None, clear_devices=True):
"""
Freezes the state of a session into a pruned computation graph.
Creates a new computation graph where variable nodes are replaced by
constants taking their current value in the session. The new graph will be
pruned so subgraphs that are not necessary to compute the requested
outputs are removed.
import tensorflow as tf
inp = tf.placeholder(name="inp", dtype=tf.float32, shape=(1, 1))
w = tf.Variable(tf.zeros([1, 1], tf.float32), dtype=tf.float32, name="w")
y = tf.matmul(w, inp)
out = tf.identity(y, name="out")
init_op = tf.global_variables_initializer()
import tensorflow as tf
inp = tf.placeholder(name="inp", dtype=tf.float32, shape=(1, 1))
w = tf.Variable(tf.zeros([1, 1], tf.float32), dtype=tf.float32, name="w")
y = tf.matmul(w, inp)
out = tf.identity(y, name="out")
init_op = tf.global_variables_initializer()
import tensorflow as tf
img = tf.placeholder(name="img", dtype=tf.float32, shape=(1))
val = img + tf.constant([1.])
out = tf.identity(val, name="out")
with tf.Session() as sess:
output = sess.run(out, feed_dict={img: [1]})
print(output)
fun <T> Single<T>.toV1(): rx.Single<T> = RxJavaInterop.toV1Single(this)
fun <T> Single<T>.toV1Observable(): rx.Observable<T> = RxJavaInterop.toV1Single(this).toObservable()
fun <T> Observable<T>.toV1(): rx.Observable<T> = RxJavaInterop.toV1Observable(this, BackpressureStrategy.BUFFER)
fun Completable.toV1(): rx.Completable = RxJavaInterop.toV1Completable(this)
fun <T> rx.Observable<T>.toV2(): io.reactivex.Observable<T> = RxJavaInterop.toV2Observable(this)

Keybase proof

I hereby claim:

  • I am miquelbeltran on github.
  • I am miquelbeltran (https://keybase.io/miquelbeltran) on keybase.
  • I have a public key whose fingerprint is 7C4D CCED CCDE B8FA F4C0 09D2 AE9F C767 BF4D 65AC

To claim this, I am signing this object:

// Sample from http://www.pacoworks.com/2018/02/25/simple-dependency-injection-in-kotlin-part-1/
interface DaoDatabase {
fun query(s: String): Any
}
class User(val id: Int)
interface DaoOperationsSyntax {
val dao: DaoDatabase
@Test
fun navigate_to_create_post_mitteilung_frage() {
ContentCreatorRobot.run {
given {
category("Mitteilung")
subCategory("Frage")
}
then {
title("Mitteilung - Frage")
subjectHintIs("Betreff")