Posts

Showing posts with the label tensorflow

Build tensorflow dataset iterator that produce batches with special structure

Image
Clash Royale CLAN TAG #URR8PPP Build tensorflow dataset iterator that produce batches with special structure As I mentioned in the title I need batches with special structure: 1111 5555 2222 Each digit represent feature-vector. So there are N=4 vectors of each classes {1,2,5} ( M=3 ) and batch size is NxM=12 . N=4 {1,2,5} M=3 NxM=12 To accomplish this task I'm using Tensorflow Dataset API and tfrecords: M N My concern is that I have hundreds (and maybe thousands in the feature) of classes and storing iterator for each class doesn't look good (from memory and performance perspective). Is there a better way? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

On Windows, running “import tensorflow” generates No module named “_pywrap_tensorflow” error

Image
Clash Royale CLAN TAG #URR8PPP On Windows, running “import tensorflow” generates No module named “_pywrap_tensorflow” error On Windows, TensorFlow reports either or both of the following errors after executing an import tensorflow statement: import tensorflow No module named "_pywrap_tensorflow" DLL load failed. 21 Answers 21 The problem was the cuDNN Library for me - for whatever reason cudnn-8.0-windows10-x64-v6.0 was NOT working - I used cudnn-8.0-windows10-x64-v5.1 - ALL GOOD! My setup working with Win10 64 and the Nvidia GTX780M: If you run Windows 32 be sure to get the 32 bit versions of the files mentioned above. It may be obvious to most but the CUDA DLL is 'cudnn64_5.dll' and the folder it is in needs to be in the path.. not the parent folder. I dropped it in '%USERPROFILE%AppDataLocalcudabin;' – Awesomeness ...

ValueError: Error when checking input: expected gru_5_input to have shape (None, None, 10) but got array with shape (1, 4, 1)

Image
Clash Royale CLAN TAG #URR8PPP ValueError: Error when checking input: expected gru_5_input to have shape (None, None, 10) but got array with shape (1, 4, 1) I am trying to make hourly predictions using a recurrent neural network using TensorFlow and Keras in Python.I have assigned my inputs of the neural network to be (None, None, 5) shown in my . However, I am getting the errorː ValueError: Error when checking input: expected gru_3_input to have shape (None, None, 10) but got array with shape (1, 4, 1) My MVCE code isː ValueError: Error when checking input: expected gru_3_input to have shape (None, None, 10) but got array with shape (1, 4, 1) %matplotlib inline #!pip uninstall keras #!pip install keras==2.1.2 import tensorflow as tf import pandas as pd from pandas import DataFrame import math import numpy from sklearn.preprocessing import MinMaxScaler from keras.models import Sequential import datetime from keras.layers import Input, Dense, GRU, Embedding from keras.optimizers import...

How to apply gradients later in tensorflow

Image
Clash Royale CLAN TAG #URR8PPP How to apply gradients later in tensorflow I have a model where I computed the gradients manually over multiple examples. I have added the gradients manually, and now would like to do back propagation in tensorflow through: prev_accum_grads = [tf.placeholder_with_default(input=tf.zeros(shape=var.get_shape().as_list(), dtype=m_dtype), shape=var.get_shape().as_list(), name=var.name[:-2] + "_accum_grads") for var in tf.trainable_variables()] grads_and_vars = list(zip(prev_accum_grads, tf.trainable_variables())) train_step = optimizer.apply_gradients(grads_and_vars) Now, given the calculated gradients in prev_g[0], prev_g[1] ... prev_g[9] as in the code below; and would like to apply the gradients as: prev_g[0], prev_g[1] ... prev_g[9] # prev_g is a list holding the values of the gradients. feed_dict = { prev_accum_grads[0]: prev_g[0], prev_accum_grads[1]: prev_g[1], pre...

How to restrict Tensorflow's weights tensor has same row variable? means under updating,still keep same

Image
Clash Royale CLAN TAG #URR8PPP How to restrict Tensorflow's weights tensor has same row variable? means under updating,still keep same I have a stupid question, but I don't know how to slove it. I have a neural network designed by tensorflow, it has several weights matrix . My output layer is a fully connected network, and it has a 2D weights matrix W. assume W is a 3x3 matrix, my algorithm need W's row value are same. means under the updating procedure, W changes to W', but each row's elements changed simultaneously and keeps same value: W= W'= [[ x,x,x], [[ x',x',x'], [ y,y,y], -> [ y',y',y'], [ z,z,z]] [ z',z',z']] means after each training step, x and y,z changes to x',y',z'. but all of 1st row's elements are x'. For 2nd and 3rd row, the rule are same. So, how do define or set this W matrix (or 2D-tensor) in tensorflow ...

How does tf.nn.ctc_greedy_decoder generates output sequences in tensorflow?

Image
Clash Royale CLAN TAG #URR8PPP How does tf.nn.ctc_greedy_decoder generates output sequences in tensorflow? Given the logits (output from the RNN/Lstm/Gru in time major format i.e. (maxTime, batchSize, numberofClasses)), how does ctc greedy decoder performs decoding to generate output sequence. I found this "Performs greedy decoding on the logits given in input (best path)" on its webpage https://www.tensorflow.org/api_docs/python/tf/nn/ctc_greedy_decoder. One possibility is to select output class with maximum value at each time step, collapse repetitions and generate corresponding output sequence. Is it, ctc greedy decoder doing here or something else? Explanation using an example will be very useful. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policie...

Keras ValueError when loading weights

Image
Clash Royale CLAN TAG #URR8PPP Keras ValueError when loading weights This is the error message I got Traceback (most recent call last): File "/home/xxx/Documents/program/test.py", line 27, in <module> model.load_weights('models/model.h5') File "/home/xxx/Documents/program/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1391, in load_weights saving.load_weights_from_hdf5_group(f, self.layers) File "/home/xxx/Documents/program/venv/lib/python3.6/site-packages/tensorflow/python/keras/engine/saving.py", line 732, in load_weights_from_hdf5_group ' layers.') ValueError: You are trying to load a weight file containing 2 layers into a model with 0 layers. From this minimal example that produces the error from tensorflow import keras from data import get_data X_train, y_train, X_val, y_val = get_data() # get some train and val data model = keras.Sequential() model.add(keras.layers.Dense(64, activa...

How to let a chatbot use a model already trained

Image
Clash Royale CLAN TAG #URR8PPP How to let a chatbot use a model already trained I am trying for the first time to build a chatbot. Following this tutorial, I already have a jupyter notebook solution that is working with a model already trained. import nltk from nltk.stem.lancaster import LancasterStemmer import numpy as np import tflearn import tensorflow as tf import random import json from ._conv import register_converters as _register_converters stemmer = LancasterStemmer() with open('intents.json') as json_data: intents = json.load(json_data) words = classes = documents = ignore_words = ['?'] # loop through each sentence in our intents patterns for intent in intents['intents']: for pattern in intent['patterns']: # tokenize each word in the sentence w = nltk.word_tokenize(pattern) # add to our words list words.extend(w) # add to documents in our corpus documents.append((w, intent['tag']...

how to fine tune faster-rcnn-resnet-101-coco model with tensorflow object detection API ?

Image
Clash Royale CLAN TAG #URR8PPP how to fine tune faster-rcnn-resnet-101-coco model with tensorflow object detection API ? I want to keep several layers in the faster rcnn resnet 101 model. And change or train the last 2 layers so I can fine it tune to my own object detection problem which have less categories. I make much efforts but failed. Firstly, the model file which the API saved did not keep the loss tensors. Secondly, there were many branches in the tensorflow op so that I can't make it clear. Maybe I should modify the source code of the API but I failed. I was lost in it. PLZ help me. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Can TensorFlow support spiking neurons?

Image
Clash Royale CLAN TAG #URR8PPP Can TensorFlow support spiking neurons? I looked around for tutorials/articles/examples/... to use spiking neurons (e.g. of the SRM/Spike Response Model type) in TensorFlow, but I could not find anything. Is it possible to simulate these models in TensorFlow at all? Can TensorFlow simulate models which explicitely depend on time? Are there any plug-ins/extensions/data files which can add this capability? Is the GPU supported? 3 Answers 3 I was also interested in this problem and have done exactly what Pietro mentioned. i.e. Took a matlab implementation of a simplified Hodgkin-Huxley model and converted it to Tensorflow. Have a look at https://github.com/jotia1/spiking-net-tensorflow https://joshuaarnold.com.au/simulating-spiking-nets-in-tensorflow/ for the blog post with some of my thoughts on the whole process. broken link Interested in hearing your thoughts on i...

Cannot freeze Tensorflow models into frozen(.pb) file

Image
Clash Royale CLAN TAG #URR8PPP Cannot freeze Tensorflow models into frozen(.pb) file I am referring (here) to freeze models into .pb file. My model is CNN for text classification I am using (Github) link to train CNN for text classification and exporting in form of models. I have trained models to 4 epoch and My checkpoints folders look as follows: I want to freeze this model into (.pb file). For that I am using following script: import os, argparse import tensorflow as tf # The original freeze_graph function # from tensorflow.python.tools.freeze_graph import freeze_graph dir = os.path.dirname(os.path.realpath(__file__)) def freeze_graph(model_dir, output_node_names): """Extract the sub graph defined by the output nodes and convert all its variables into constant Args: model_dir: the root folder containing the checkpoint state file output_node_names: a string, containing all the output node's names, comma separ...

keras try save and load model error

Image
Clash Royale CLAN TAG #URR8PPP keras try save and load model error i am trying to fine tuning and save model in Keras and load model but error Value Error: You are trying to load a weight file containing 16 layers into a model with 0 layers. i tried another model for number i made it save and load mode work without error when i try adopt vgg16 and used it give that error i want load model but cant load because this error any help ? Value Error: You are trying to load a weight file containing 16 layers into a model with 0 layers. import keras from keras.models import Sequential,load_model,model_from_json from keras import backend as K from keras.layers import Activation,Conv2D,MaxPooling2D,Dropout from keras.layers.core import Dense,Flatten from keras.optimizers import Adam from keras.metrics import categorical_crossentropy from keras.layers.normalization import BatchNormalization from keras.layers.convolutional import * from keras.preprocessing.image import ImageDataGenerator import m...