theano

Saliency maps of neural networks (using Keras)

你说的曾经没有我的故事 提交于 2019-12-02 18:33:14
I have a fully connected multilayer perceptron trained in Keras. I feed it an N-dimensional feature vector and it predicts one out of M classes for the input vector. The training and prediction is working well. Now I want to analyze what part of the input feature vector is actually responsible for a particular class. For example, lets say there are two classes A and B , and an input vector f . The vector f belongs to class A and the network predicts it correctly - the output of the network is A=1 B=0 . Because I have some domain knowledge, I know that the entire f is actually not responsible

Keras uses way too much GPU memory when calling train_on_batch, fit, etc

自作多情 提交于 2019-12-02 17:55:29
I've been messing with Keras, and like it so far. There's one big issue I have been having, when working with fairly deep networks: When calling model.train_on_batch, or model.fit etc., Keras allocates significantly more GPU memory than what the model itself should need. This is not caused by trying to train on some really large images, it's the network model itself that seems to require a lot of GPU memory. I have created this toy example to show what I mean. Here's essentially what's going on: I first create a fairly deep network, and use model.summary() to get the total number of parameters

Error running theano.test() - ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed

非 Y 不嫁゛ 提交于 2019-12-02 17:53:18
问题 I'm trying to get theano up and running on a Windows 10 (x64) machine. I've installed Python from the WinPython distribution, which comes with theano already running. But after installing CUDA 8.0.44 and MingW, I constantly get the following errors when running the simple script import theano theano.test() Note that I had several warnings before, that I already solved (e.g. by installing missing packages from here. But this error gives me no usable information. The really weird thing is, that

Python: rewrite a looping numpy math function to run on GPU

浪尽此生 提交于 2019-12-02 17:36:30
Can someone help me rewrite this one function (the doTheMath function) to do the calculations on the GPU? I used a few good days now trying to get my head around it but to no result. I wonder maybe somebody can help me rewrite this function in whatever way you may seem fit as log as I gives the same result at the end. I tried to use @jit from numba but for some reason it is actually much slower than running the code as usual. With a huge sample size, the goal is to decrease the execution time considerably so naturally I believe the GPU is the fastest way to do it. I'll explain a little what is

常用python机器学习库总结

佐手、 提交于 2019-12-02 17:08:42
原文地址:https://www.cnblogs.com/Fighting365/p/6132707.html 开始学习Python,之后渐渐成为我学习工作中的第一辅助脚本语言,虽然开发语言是Java,但平时的很多文本数据处理任务都交给了Python。这些年来,接触和使用了很多Python工具包,特别是在文本处理,科学计算,机器学习和数据挖掘领域,有很多很多优秀的Python工具包可供使用,所以作为Pythoner,也是相当幸福的。如果仔细留意微博和论坛,你会发现很多这方面的分享,自己也Google了一下,发现也有同学总结了“Python机器学习库”,不过总感觉缺少点什么。最近流行一个词,全栈工程师(full stack engineer),作为一个苦逼的程序媛,天然的要把自己打造成一个full stack engineer,而这个过程中,这些Python工具包给自己提供了足够的火力,所以想起了这个系列。当然,这也仅仅是抛砖引玉,希望大家能提供更多的线索,来汇总整理一套Python网页爬虫,文本处理,科学计算,机器学习和数据挖掘的兵器谱。 1. Python网页爬虫工具集 一个真实的项目,一定是从获取数据开始的。无论文本处理,机器学习和数据挖掘,都需要数据,除了通过一些渠道购买或者下载的专业数据外,常常需要大家自己动手爬数据,这个时候,爬虫就显得格外重要了,幸好

How do I implement the optimization function in tensorflow?

二次信任 提交于 2019-12-02 17:05:09
问题 minΣ(||xi-X ci||^2+ λ ||ci||), s.t cii = 0, where X is a matrix of shape d * n and C is of the shape n * n, xi and ci means a column of X and C separately. X is known here and based on X we want to find C. 回答1: Usually with a loss like that you need to vectorize it, instead of working with columns: loss = X - tf.matmul(X, C) loss = tf.reduce_sum(tf.square(loss)) reg_loss = tf.reduce_sum(tf.square(C), 0) # L2 loss for each column reg_loss = tf.reduce_sum(tf.sqrt(reg_loss)) total_loss = loss +

How to Switch from Keras Tensortype to numpy array for a custom layer?

戏子无情 提交于 2019-12-02 16:45:59
问题 So I have a custom layer, that does not have any weights. In a fist step, I tried to implement the functions manipulating the input tensors in Kers. But I did not succeed because of many reasons. My second approach was to implement the functions with numpy operations, since the custom layer I am implementing does not have any weights, from my understanding, I would say, that I could use numpy operarations, as I don't need backpropagation, since there are no weights, right? And then, I would

Unsupervised pre-training for convolutional neural network in theano

拜拜、爱过 提交于 2019-12-02 16:12:27
I would like to design a deep net with one (or more) convolutional layers (CNN) and one or more fully connected hidden layers on top. For deep network with fully connected layers there are methods in theano for unsupervised pre-training, e.g., using denoising auto-encoders or RBMs . My question is: How can I implement (in theano) an unsupervised pre-training stage for convolutional layers? I do not expect a full implementation as an answer, but I would appreciate a link to a good tutorial or a reliable reference. This paper describes an approach for building a stacked convolutional autoencoder

How to add and remove new layers in keras after loading weights?

帅比萌擦擦* 提交于 2019-12-02 15:31:29
I am trying to do a transfer learning; for that purpose I want to remove the last two layers of the neural network and add another two layers. This is an example code which also output the same error. from keras.models import Sequential from keras.layers import Input,Flatten from keras.layers.convolutional import Convolution2D, MaxPooling2D from keras.layers.core import Dropout, Activation from keras.layers.pooling import GlobalAveragePooling2D from keras.models import Model in_img = Input(shape=(3, 32, 32)) x = Convolution2D(12, 3, 3, subsample=(2, 2), border_mode='valid', name='conv1')(in

Keras model.summary() result - Understanding the # of Parameters

和自甴很熟 提交于 2019-12-02 14:17:40
I have a simple NN model for detecting hand-written digits from a 28x28px image written in python using Keras (Theano backend): model0 = Sequential() #number of epochs to train for nb_epoch = 12 #amount of data each iteration in an epoch sees batch_size = 128 model0.add(Flatten(input_shape=(1, img_rows, img_cols))) model0.add(Dense(nb_classes)) model0.add(Activation('softmax')) model0.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy']) model0.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch, verbose=1, validation_data=(X_test, Y_test)) score = model0