Posts

Showing posts with the label tensorflow

gensim function predict output words

gensim function predict output words I use the gensim library to create a word2vec model. It contains the function predict_output_words() which I understand as follows: predict_output_words() For example, I have a model that is trained with the sentence: "Anarchism does not offer a fixed body of doctrine from a single particular world view instead fluxing and flowing as a philosophy." and then I use model.predict_output_words(context_words_list=['Anarchism', 'does', 'not', 'offer', 'a', 'fixed', 'body', 'of', 'from', 'a', 'single', 'particular', 'world', 'view', 'instead', 'fluxing'], topn=10) . model.predict_output_words(context_words_list=['Anarchism', 'does', 'not', 'offer', 'a', 'fixed', 'body', 'of', 'from', 'a', 'single', 'particular', 'world...

LSTM neural network for multiple steps time series prediction

LSTM neural network for multiple steps time series prediction I tried to develop a model that foresees two time-steps forward In this regard I modified a GitHub code for the single step forecast coding a data_load function that takes n steps backward in the X_train/test series and set it against a y_train/test 2-array. data_load n steps X_train/test y_train/test I set the neurons list to output in Dense a 2-vector object. And last I wrote a predict function and a plot function for the 2-step-forecast. I do not normalized features lables and forecasts I will do in the future. After a bit of hyperfine tuning it returns a good score for the mse and rmse: Train Score: 0.00000 MSE (0.00 RMSE) Test Score: 0.00153 MSE (0.04 RMSE) It can find quite well the trend, but it returns all forecasts with negative directions. Does anyone have a suggestion? import seaborn as sns import numpy as np import matplotlib.pyplot as plt import matplotlib.pyplot as plt2 import pandas as pd from pandas imp...

why keras model param values change when it is accessed in a tensorflow session?

why keras model param values change when it is accessed in a tensorflow session? I was having trouble with my transfer learning implementation. I guess I found the root cause but it is not clear to me why it works like that. Here is the explanation... If I create a model (e.g. resnet50 from keras.applications), and then try to use it in a tensorflow session, weights all of a sudden change. Here is a simple example: First import the necessary libraries: import tensorflow as tf from keras.applications.resnet50 import ResNet50 from keras.models import Model Then define the model as following: model = ResNet50(weights='imagenet') Now print out parameters from one of the layers as following: model.get_layer('conv1').get_weights() The output is long but it starts as following: [array([[[[ 2.82526277e-02, -1.18737184e-02, 1.51488732e-03, ..., -1.07003953e-02, -5.27982824e-02, -1.36667420e-03], [ 5.86827798e-03, 5.04415408e-02, 3.46324709e-03, ..., ...

How to compute Pairwise L1 Distance matrix on very large images in neighborhood only?

Image
How to compute Pairwise L1 Distance matrix on very large images in neighborhood only? I am working on Deep learning approach for my project. And I need to calculate Distance Matrix on 4D Tensor which will be of size N x 128 x 64 x 64 (Batch Size x Channels x Height x Width) . The distance matrix for this type of tensor will of size N x 128 x 4096 x 4096 and it will be impossible to fit this type of tensor in GPU, even on CPU it will require lot of memory. So, I would like to calculate the distance matrix only in some neighborhood pixels (say within radius of 5) and consider this rectangular matrix for further processing in neural network. With this approach my distance matrix will be of size N x 128 x 4096 x 61 . It will take less memory in comparison to full distance matrix. Precisely, I am trying to implement the Convolution Random Walk Networks for Semantic Segmentation. This network needs to calculate the Pairwise L1 Distance for features. Architecture Just to add this type of Di...

TFLearn example code gives invalid placeholder error

TFLearn example code gives invalid placeholder error The code for a Convolutional Neural Network using TFLearn at https://github.com/tflearn/tflearn/blob/master/examples/images/convnet_mnist.py does not work. When run, it gives an error: You must feed a value for placeholder tensor 'TargetsData/Y' with dtype float and shape [?] I have the same problem when running other TFLearn examples. Can someone please tell me how to fix this? 1 Answer 1 The code example worked fine for me using tflearn version 0.3.2. But, I reproduced the same error when re-running the code without restarting the kernel of a Jupyter notebook or reseting the default graph. Insert the following lines of code: import tensorflow as tf tf.reset_default_graph() ## Building Convolutional Network # ... By clicking "Post Your Answer", you acknowledge that you have read our up...

tf.gather_nd is really slow when used for many times

tf.gather_nd is really slow when used for many times I would like a loss function in tensorflow which is a complex combination of many elements. For example, this code: import tensorflow as tf import numpy as np import time input_layer = tf.placeholder(tf.float64, shape=[64,4]) output_layer = input_layer + 0.5*tf.tanh(tf.Variable(tf.random_uniform(shape=[64,4], minval=-1,maxval=1,dtype=tf.float64))) # random_combination is 2-d numpy array of the form: # [[32, 34, 23, 56],[23,54,33,21],...] random_combination = np.random.randint(64, size=(210000000, 4)) # a collector to collect the values collector= print('start looping') print(time.asctime(time.localtime(time.time()))) # loop through random_combination and pick the elements of output_layer for i in range(len(random_combination)): [i,j,k,l] = [random_combination[i][0],random_combination[i][1], random_combination[i][2],random_combination[i][3]] # pi...

Object Detection Inventory Management

Object Detection Inventory Management So I am doing research for a professor at my college and he wants me to learn object detection using a camera. He has assigned me with the task of creating an inventory management system where there would be 3 bins with certain objects in each bin (Ex. Bin 1 = 5 oranges, bin 2 = 8 bananas, bin 3 = 10 apples). Now when someone picks something up from one of these bins, the computer would subtract the count of the objects from the corresponding bin and update the total number of objects in the bin to the computer and vise versa for adding objects. So my question is what the best path of action is. I have currently installed tenorflow onto my pc and have got the object detection api working. I am familiar with some basic python but am completely new to machine learning. This is my first real project in the computer science field and I am not sure how to go about coding this. Thanks for all your help! -Gubi I dont think t...

ResourceExhaustedError With CNN

ResourceExhaustedError With CNN I am trying to complete this tutorial with this source code I have tried using their large images data as well as my own small data set of 52 images (46x46) but I keep running into ResourceExhaustedError ResourceExhaustedError OOM when allocating tensor with shape[1016064,1024] Is there any way I can edit this code so it trains on smaller training sets so I dont run into this error? I have tried changing batch sizes in the code but this accomplished nothing. I also made sure I dont have any previous tensorflow projects running (i restarted my computer) my label.txt contains these two lines: cat dog and my train and validation folders contain 2 subfolders with the same name that contain the images. I am using: GeForce GTX 850M major: 5 minor: 0 memoryClockRate(GHz): 0.9015 totalMemory: 4.00GiB freeMemory: 3.35GiB before I hit the error I get this print out: Limit: 3235767910 InUse: 223232 MaxInUse: ...

How to setup a basic .gitlab-ci.yml file for CI/CD for a Python project using TensorFlow and OpenAI gym on GitLab?

How to setup a basic .gitlab-ci.yml file for CI/CD for a Python project using TensorFlow and OpenAI gym on GitLab? I think that the title is self explanatory. I'm currently developing a project in python3 using TensorFlow and OpenAI gym. I've already used some basic .gitlab-ci.yml offered from GitLab for other projects involving other languages but I've found nothing about Python projects with TensorFlow. .gitlab-ci.yml I know that this seems a classical do it for me question without research on the problem nor code. I tried to find something to start from online but I found nothing. If you don't want to provide a full answer is fine but please, if you can, give me some hint to start working. – gvgramazio Jul 1 at 20:53 By clicking "Post Your Answer...

Issues in order to adapt label_image.py

Issues in order to adapt label_image.py I'd like to modify label_image.py, my main goal is to create a GUI. Some words about my ideas I'm trying to modify some stuffs in the code (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/label_image/label_image.py), but it doesn't work. I first tried to had a filename = askopenfilename() line, which it seems to work. filename = askopenfilename() Then I don't know how I can adapt the code. For example, in order to load MY graph, which line have I to adapt? Maybe line 26 : def load_graph(model_file) : and putting def load_graph("c:my_path_hereowngraph.pb): ? It doesn't work either. def load_graph(model_file) : def load_graph("c:my_path_hereowngraph.pb): I have the same question for label, and also for the choosen picture: filename = askopenfilename() --> where can I load MY picture (I tried to replace all file_name by filename but it fails). filename = askopenfilename() file_name filen...

How to train Actor-Critic (A2C) reinforcement learning

How to train Actor-Critic (A2C) reinforcement learning I am currently been able to train a system using Q-Learning. I will to move it to Actor_Critic (A2C) method. Please don't ask me why for this move, I have to. I am currently borrowing the implementation from https://github.com/higgsfield/RL-Adventure-2/blob/master/1.actor-critic.ipynb The thing is, I am keep getting a success rate of approx ~ 50% (which is basically random behavior). My game is a long episode (50 steps). Should I print out the reward, the value, or what? How should I debug this? Here are some log: simulation episode 2: Success, turn_count =20 loss = tensor(1763.7875) simulation episode 3: Fail, turn_count= 42 loss = tensor(44.6923) simulation episode 4: Fail, turn_count= 42 loss = tensor(173.5872) simulation episode 5: Fail, turn_count= 42 loss = tensor(4034.0889) simulation episode 6: Fail, turn_count= 42 loss = tensor(132.7567) loss = simulation episode 7: Success, turn_count =22 loss = tensor(2099.5344) ...