estudiante
estudiante

Reputation: 45

how can i implement or convert a python code to javascript to be used with tensorflow js

how could I use this code in python with tensorflow js? it is to occupy it with a model that was trained with the dataset tf.keras.applications.ResNet152(input_shape=(256,256,3),weights='imagenet', include_top=False, classes=numClasses)

I can't find information

#ONE IMAGE PREDICTION

url = "https://images.unsplash.com/photo-1577705998148-6da4f3963bc8?ixid=MnwxMjA3fDB8MHxzZWFyY2h8Nnx8Y2FyZGJvYXJkfGVufDB8fDB8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=500&q=60"

 image = tf.keras.utils.get_file("Image1.jpg", origin=url)
    
    img = tf.keras.preprocessing.image.load_img(image, target_size=(256,256))
    img_array = tf.keras.preprocessing.image.img_to_array(img)
    img_array = tf.expand_dims(img_array,0)
    
    predictions = model.predict(img_array)

Upvotes: 0

Views: 147

Answers (1)

estudiante
estudiante

Reputation: 45

in case it helps someone, use these tensorflow js functions

var img="";
          img=document.getElementById("myImage3"); //<img src='myImage'/>
          x = tf.browser.fromPixels(img);
        var readyfied = tf.image
        .resizeBilinear(x, [256, 256], true)
        .div(255)
        .reshape([1, 256, 256, 3]);

        x=tf.expandDims(x,0);
        x.print();
         res= this.model.predict(readyfied);

Upvotes: 0

Related Questions