tensorflow

Split image tensor into small patches

谁说胖子不能爱 提交于 2021-02-07 07:12:26
问题 I have an image of shape (466,394,1) which I want to split into 7x7 patches. image = tf.placeholder(dtype=tf.float32, shape=[1, 466, 394, 1]) Using image_patches = tf.extract_image_patches(image, [1, 7, 7, 1], [1, 7, 7, 1], [1, 1, 1, 1], 'VALID') # shape (1, 66, 56, 49) image_patches_reshaped = tf.reshape(image_patches, [-1, 7, 7, 1]) # shape (3696, 7, 7, 1) unfortunately does not work in practice as image_patches_reshaped mixes up the pixel order (if you view images_patches_reshaped you will

Split image tensor into small patches

若如初见. 提交于 2021-02-07 07:11:53
问题 I have an image of shape (466,394,1) which I want to split into 7x7 patches. image = tf.placeholder(dtype=tf.float32, shape=[1, 466, 394, 1]) Using image_patches = tf.extract_image_patches(image, [1, 7, 7, 1], [1, 7, 7, 1], [1, 1, 1, 1], 'VALID') # shape (1, 66, 56, 49) image_patches_reshaped = tf.reshape(image_patches, [-1, 7, 7, 1]) # shape (3696, 7, 7, 1) unfortunately does not work in practice as image_patches_reshaped mixes up the pixel order (if you view images_patches_reshaped you will

How could I convert onnx model to tensorflow saved model?

感情迁移 提交于 2021-02-07 06:56:43
问题 I am trying to use tf-serving to deploy my torch model. I have exported my torch model to onnx. How could I generate the pb model for tf-serving ? 回答1: Use the onnx/onnx-tensorflow converter tool as a Tensorflow backend for ONNX. Install onnx-tensorflow: pip install onnx-tf Convert using the command line tool: onnx-tf convert -t tf -i /path/to/input.onnx -o /path/to/output.pb Alternatively, you can convert through the python API. import onnx from onnx_tf.backend import prepare onnx_model =

How could I convert onnx model to tensorflow saved model?

耗尽温柔 提交于 2021-02-07 06:56:21
问题 I am trying to use tf-serving to deploy my torch model. I have exported my torch model to onnx. How could I generate the pb model for tf-serving ? 回答1: Use the onnx/onnx-tensorflow converter tool as a Tensorflow backend for ONNX. Install onnx-tensorflow: pip install onnx-tf Convert using the command line tool: onnx-tf convert -t tf -i /path/to/input.onnx -o /path/to/output.pb Alternatively, you can convert through the python API. import onnx from onnx_tf.backend import prepare onnx_model =

Tensorflow: Why my code is running slower and slower?

一曲冷凌霜 提交于 2021-02-07 06:44:27
问题 I am new to tensorflow. The following code can run successfully, without any error. In the first 10 lines of output, the computation is fast, and the output (defined in the last line) flies line by line. However, as the iteration goes up, the computation become slower and slower, and finally become intolerable. So I wonder whether there are any modifications that can speed this up. Here is a brief description of this code: This code apply the single hidden-layer neural network to the dataset.

Keras predict loop memory leak using tf.data.Dataset but not with a numpy array

大兔子大兔子 提交于 2021-02-07 06:43:17
问题 I encounter a memory leak and decreasing performance when looping over a Keras model predict function when using a tf.data.Dataset to feed the model, but not when feeding it with a numpy array. Does anyone understand what is causing this and/or how to resolve the issue? Minimal reproducible code snippet (copy/paste runnable): import tensorflow as tf import numpy as np import time SIZE = 5000 inp = tf.keras.layers.Input(shape=(SIZE,), dtype='float32') x = tf.keras.layers.Dense(units=SIZE)(inp)

Why are my results still not reproducible?

≯℡__Kan透↙ 提交于 2021-02-07 06:39:11
问题 I want to get reproducible results for a CNN. I use Keras and Google Colab with GPU. In addition to recommendations to insert certain code snippets, which should allow a reproducibility, I also added seeds to the layers. ###### This is the first code snipped to run ##### !pip install -U -q PyDrive from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive from google.colab import auth from oauth2client.client import GoogleCredentials # Authenticate and create the PyDrive client

Heroku: deploying Deep Learning model

岁酱吖の 提交于 2021-02-07 06:17:27
问题 I have developed a rest API using Flask to expose a Python Keras Deep Learning model (CNN for text classification). I have a very simple script that loads the model into memory and outputs class probabilities for a given text input. The API works perfectly locally. However, when I git push heroku master , I get Compiled slug size: 588.2M is too large (max is 500M) . The model is 83MB in size, which is quite small for a Deep Learning model. Notable dependencies include Keras and its tensorflow

'AutoTrackable' object is not callable in Python

不羁的心 提交于 2021-02-07 05:42:25
问题 My tensorflow version is 2.0 tensorflow_hub version is 0.7 python version is 3.7 I have these code import tensorflow as tf import tensorflow_hub as hub import summarizer_data_utils specials = ["<EOS>", "<SOS>","<PAD>","<UNK>"] word2ind, ind2word, missing_words = summarizer_data_utils.create_word_inds_dicts(words_counted, specials = specials) #embed = hub.Module("https://tfhub.dev/google/nnlm-en-dim128/1") embed = hub.load("https://tfhub.dev/google/Wiki-words-250/1") emb = embed([key for key

Single Thread Impacts Model Accuracy and Loss with TensorFlow Keras Backend

瘦欲@ 提交于 2021-02-07 05:36:11
问题 Question Why does setting the number of threads in the TensorFlow backend for Keras, intra_op_parallelism_threads and inter_op_parallelism_threads, to 1 negatively impact the accuracy and loss of a model? Background I am using Keras (2.1.6) to train an MNIST CNN with TensorFlow (1.7.0) as the backend. I was running some training in an AWS EC2 instance and noticed my accuracy decreased greatly after switching from a t2.medium instance to a t2.small. This happened without changing the code at