{"QuestionId": 35993175, "AnswerCount": 1, "Tags": "", "CreationDate": "2016-03-14T16:39:19.020", "AcceptedAnswerId": "36005826", "Title": "How can I get two output values (for each of the two classes) for a binary classifier in Caffe?", "Body": "

I'm experimenting with LeNet network as a binary classifier (yes, no).\nThe first and several last layers in the configuration file for testing is the following:

\n\n
    layer {\n      name: \"data\"\n      type: \"ImageData\"\n      top: \"data\"\n      top: \"label\"\n      include {\n        phase: TEST\n      }\n      transform_param {\n        scale: 0.00390625\n      }\n      image_data_param {\n        source: \"examples/my_example/test_images_labels.txt\"\n        batch_size: 1\n        new_height: 128\n        new_width: 128\n      }\n    }\n...\n    layer {\n      name: \"ip2\"\n      type: \"InnerProduct\"\n      bottom: \"ip1\"\n      top: \"ip2\"\n      param {\n        lr_mult: 1\n      }\n      param {\n        lr_mult: 2\n      }\n      inner_product_param {\n        num_output: 2\n        weight_filler {\n          type: \"xavier\"\n        }\n        bias_filler {\n          type: \"constant\"\n        }\n      }\n    }\n    layer {\n      name: \"accuracy\"\n      type: \"Accuracy\"\n      bottom: \"ip2\"\n      bottom: \"label\"\n      top: \"accuracy\"\n    }\n    layer {\n      name: \"loss\"\n      type: \"SoftmaxWithLoss\"\n      bottom: \"ip2\"\n      bottom: \"label\"\n      top: \"loss\"\n    }\n
\n\n

For testing I've set the batch_size=1, thus I ran testing with the following command:

\n\n
./build/tools/caffe test -model examples/my_example/lenet_test.prototxt -weights=examples/my_example/lenet_iter_528.caffemodel -iterations 200\n
\n\n

My intent is to be able to analyze result for each test image separately.\nCurrently I get the following info for each iteration:

\n\n
\n
I0310 18:30:21.889688  5952 caffe.cpp:264] Batch 41, accuracy = 1\nI0310 18:30:21.889739  5952 caffe.cpp:264] Batch 41, loss = 0.578524\n
\n
\n\n

However since I have two outputs in my network, on testing I want to see two separate values for each of the outputs: one for class \"0\" (\"no\") and one for class \"1\" (\"yes\"). It should be something like that:

\n\n
\n
Batch 41, class 0 output: 0.755\nBatch 41, class 1 output: 0.201\n
\n
\n\n

How should I modify the testing configuration file to make it happen?

\n", "Lable": "D"} {"QuestionId": 36033877, "AnswerCount": 1, "Tags": "", "CreationDate": "2016-03-16T11:07:38.423", "AcceptedAnswerId": null, "Title": "How to fetch images from database dynamically?", "Body": "

I am trying to fetch images from my database, i can fetch images manually one by one. The code below is asp.net and its C#:

\n\n
  <asp:Image ID=\"img1\" runat=\"server\" />\n            <asp:Image ID=\"img2\" runat=\"server\" />\n            <asp:Image ID=\"img3\" runat=\"server\" />\n            <asp:Image ID=\"Image3\" runat=\"server\" />\n            <asp:Image ID=\"img4\" runat=\"server\" />\n            <asp:Image ID=\"img5\" runat=\"server\" />\n            <asp:Image ID=\"img6\" runat=\"server\" />\n            <asp:Image ID=\"Image7\" runat=\"server\" />\n            <asp:Image ID=\"Image8\" runat=\"server\" />\n            <asp:Image ID=\"Image9\" runat=\"server\" />\n\n\n    dr.Read();\n    img1.ImageUrl = \"~/Resimler/800/\" + dr[2].ToString();\n    dr.Read();\n    img2.ImageUrl = \"~/Resimler/800/\" + dr[2].ToString();\n    dr.Read();\n    img3.ImageUrl = \"~/Resimler/800/\" + dr[2].ToString();\n    dr.Read();\n    img4.ImageUrl = \"~/Resimler/800/\" + dr[2].ToString();\n    dr.Read();\n    img5.ImageUrl = \"~/Resimler/800/\" + dr[2].ToString();\n    dr.Read();\n    img6.ImageUrl = \"~/Resimler/800/\" + dr[2].ToString();\n
\n\n

So i want to fetch images dynamically.

\n", "Lable": "No"} {"QuestionId": 36094842, "AnswerCount": 3, "Tags": "", "CreationDate": "2016-03-18T21:51:45.973", "AcceptedAnswerId": null, "Title": "How to force a Python's function to accept a certain input?", "Body": "

Regardless of whether it's a good idea or not, I wanted to know whether it would be possible to force a method to accept a certain input, for example a character without quotes (\"!\"). Exempli gratia:

\n\n
def special_print(text):\n    \"\"\"Print <text> unless ! (no quotes!) is passed as argument.\"\"\"\n    if text == !:\n        print(\"Easter egg!\")\n    else:\n        print(text)\n\n\nspecial_print(\"Hello, World\"!)\n>>> Hello, World!\n\nspecial_print(\"!\")\n>>> !\n\nspecial_print(!)\n>>> Easter egg!\n
\n\n

Would that be possible? Just curious.

\n", "Lable": "No"} {"QuestionId": 36169551, "AnswerCount": 1, "Tags": "", "CreationDate": "2016-03-23T03:54:45.080", "AcceptedAnswerId": null, "Title": "Simple jQuery filtering", "Body": "

So I have few categories that I would like to my news to filter.

\n\n

My HTML currently:

\n\n
<div class=\"filters\">\n    <a href=\"#\" data-filters=\"1,2,3,4\">All</a> \n    <a href=\"#\" data-filters=\"3,4\">Audi, Mercedes Benz</a> \n    <a href=\"#\" data-filters=\"4\">Ferrari</a> \n    <a href=\"#\" data-filters=\"1,3,4\">Alfa-Romeo Audi, Mercedes-Benz</a>\n</div>\n\n<div id=\"news\">\n    <article data-filters=\"1,2\">\n        <h1></h1>\n    </article>\n    <article data-filters=\"2\">\n        <h1></h1>\n    </article>\n    <article data-filters=\"1,2,3,4\">\n        <h1></h1>\n    </article>\n    <article data-filters=\"3\">\n        <h1></h1>\n    </article>\n    <article data-filters=\"4\">\n        <h1></h1>\n    </article>\n</div>\n
\n\n

So what I would like to achieve is if users click \"Ferrari\" filter, it would then only show articles that has id \"4\" in filters attribute. But then if user clicks \"Alfa-Romea, Audi, Mercedes-Benz\" filter, then it would show only articles with \"1,3,4\" ids in filters attribute.

\n\n

Simple filter with only one id I can achieve like this:

\n\n
$('.filters a').click(function() {\n    var toFilter = $(this).data('filters');\n\n    $('.news article').each(function(i,elem) {\n        var filters = $(this).data('filters');\n\n        if ( filters == toFilter ) {\n            $(this).addClass('hidden');\n        }\n    )};\n});\n
\n\n

But in my case sometime in filters I have multiple IDs so how should I modify my jQuery?

\n", "Lable": "No"} {"QuestionId": 36245065, "AnswerCount": 2, "Tags": "", "CreationDate": "2016-03-27T07:48:01.590", "AcceptedAnswerId": null, "Title": "Building a simple image search using TensorFlow", "Body": "

I need to implement a simple image search in my app using TensorFlow.\nThe requirements are these:

\n\n
    \n
  1. The dataset contains around a million images, all of the same size, each containing one unique object and only that object.
  2. \n
  3. The search parameter is an image taken with a phone camera of some object that is potentially in the dataset.
  4. \n
\n\n

I've managed to extract the image from the camera picture and straighten it to rectangular form and as a result, a reverse-search image indexer like TinEye was able to find a match.

\n\n

Now I want to reproduce that indexer by using TensorFlow to create a model based on my data-set (make each image's file name a unique index).

\n\n

Could anyone point me to tutorials/code that would explain how to achieve such thing without diving too much into computer vision terminology?

\n\n

Much appreciated!

\n", "Lable": "D"} {"QuestionId": 36284655, "AnswerCount": 0, "Tags": "", "CreationDate": "2016-03-29T12:43:56.053", "AcceptedAnswerId": null, "Title": "Foundation 6 range slider bug", "Body": "

I'm using Foundation 6 to create a website for a gaming community, and one of the features on the website is the ability to donate to the server.

\n\n

The donation amount is chosen using a slider which should span from 1-10 EUR. However, you are unable to drag the slider all the way to 10, it just stops at 9.\nI am able to move the slider handle to ten if I move it using the arrow keys, or by changing the value in the number input above the slider.

\n\n

Here's a small gif showing the bug

\n\n

\"enter

\n\n

All the other foundation javascript plugins seems to work as intended, the code for the slider is as follows:

\n\n
<input type=\"text\" id=\"sliderOutput2\" style=\"margin-top: 2em;width:4em;margin-left: auto; margin-right: auto; text-align: center; font-weight: bolder;\">\n            <div class=\"slider\" data-slider data-initial-start=\"5\" data-start=\"1\" data-end=\"10\" data-decimal=\"0\">\n                <span class=\"slider-handle\"  data-slider-handle role=\"slider\" tabindex=\"1\" aria-controls=\"sliderOutput2\"></span>\n                <span class=\"slider-fill\" data-slider-fill></span>\n            </div>\n
\n\n

with the input at the top being the visual representation of the slider value.\nThis code is pretty much taken directly from the example on the Foundation documentation (Foundation Range Slider Docs)

\n\n

And here is all my jquery/javascript links

\n\n
<script src=\"/js/vendor/jquery.min.js\"></script>\n<script src=\"/js/vendor/what-input.min.js\"></script>\n<script src=\"/js/foundation.min.js\"></script>\n<script src=\"/js/app.js\"></script>\n<script src=\"/js/jstz.min.js\"></script>\n<script src=\"/js/discord-widget.js\"></script>\n<script src=\"/js/forum-replyBox.js\"></script>\n<script src=\"/ckeditor/ckeditor.js\"></script>\n<script type=\"text/javascript\">\nCKEDITOR.replace( 'forumEditor', {\n    qtWidth: '100%'\n}); \n</script>\n<script src=\"/js/registrationFormValidation.js\"></script>\n<script src=\"/js/hSlider.js\"></script>\n<script src=\"/js/playerCount.js\"></script>\n<script     src=\"http://cdnjs.cloudflare.com/ajax/libs/jstimezonedetect/1.0.4/jstz.min.js\">    </script>\n<script src=\"/js/shoutbox.js\"></script>\n<?php if(!isset($_SESSION['timezone'])) echo '<script src=\"/js/updateTimezone.js\"></script>';?>\n<script src=\"/js/inlineSVGimg.js\"></script>\n<script type=\"text/javascript\">\n//removes all loading bars\n$(window).on(\"load\", function(){\n    console.log($(\".sk-cube-grid\").remove());\n});\n</script>\n<script type=\"text/javascript\">\n$('#dropdownmenu').on(\n'show.zf.dropdownmenu', function() {\n  var dropdown = $(this).find('.is-dropdown-submenu');\n  dropdown.css('display', 'none');\n  dropdown.fadeIn('fast');\n});\n$('#dropdownmenu').on(\n'hide.zf.dropdownmenu', function() {\n  var dropdown = $(this).find('.is-dropdown-submenu');\n  dropdown.css('display', 'inherit');\n  dropdown.fadeOut('fast');\n});\n</script>\n
\n\n

If you need more information about my implementation of the Foundation framework, please ask

\n\n

Thanks in advance,\nRegards\nDaniel Holst

\n", "Lable": "No"} {"QuestionId": 36324061, "AnswerCount": 3, "Tags": "", "CreationDate": "2016-03-31T04:17:13.813", "AcceptedAnswerId": "36324154", "Title": "Difference between two rows with date in ascending order", "Body": "

I am trying to write a query which calculates the difference between the value rows as a new column called difference when the datetime field is in ascending order.

\n\n

For example, 2016-03-02 should be 102340624 - 102269208

\n\n
select datetime, tagname, value\nfrom runtime.dbo.AnalogHistory\nwhere datetime between '20160301 00:00' and '20160401 00:00'\nand TagName = 'EWS_A3_PQM.3P_REAL_U'\nand wwResolution = (1440 * 60000)\norder by DateTime asc\n\nDATETIME                    TAGNAME                 VALUE       DIFFERENCE\n2016-03-01 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102269208\n2016-03-02 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102340624\n2016-03-03 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102411568\n2016-03-04 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102478104\n2016-03-05 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102549088\n2016-03-06 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102612592\n2016-03-07 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102682984\n2016-03-08 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102747000\n2016-03-09 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102817176\n2016-03-10 00:00:00.0000000 EWS_A3_PQM.3P_REAL_U    102887896\n
\n\n

Thank you very much in advance

\n", "Lable": "No"} {"QuestionId": 36361679, "AnswerCount": 2, "Tags": "", "CreationDate": "2016-04-01T16:47:26.930", "AcceptedAnswerId": "36362034", "Title": "Primitive Python IRC Chat bot for twitch", "Body": "

I'm currently working on an IRC bot for Twitch.tv and I was wondering how I can implement a banned words list? Here is what I have so far and I'm stumped because of my limited knowledge of python. Everything is working great so far except checking to see if banned words are in the message. This is the bit of code in question:

\n\n
if bannedWords.split in message:\n                sendMessage(s, \"/ban \" + user)\n                break\n
\n\n

I was thiking of checking a list to see if the message containts anything from the list?

\n\n
bannedWords = [\"badword1\", \"badword1\"]\n
\n\n

But I'm just not sure..

\n\n
import string\nfrom Read import getUser, getMessage\nfrom Socket import openSocket, sendMessage\nfrom Initialize import joinRoom\n\ns = openSocket()\njoinRoom(s)\nreadbuffer = \"\"\nbannedWords = [\"badword1\", \"badword1\"]\nwhile True:\n        readbuffer = readbuffer + s.recv(1024)\n        temp = string.split(readbuffer, \"\\n\")\n        readbuffer = temp.pop()\n\n        for line in temp:\n            print(line)\n            if \"PING\" in line:\n                s.send(line.replace(\"PING\", \"PONG\"))\n                break\n            user = getUser(line)\n            message = getMessage(line)\n            print user + \" typed :\" + message\n            if bannedWords.split in message:\n                sendMessage(s, \"/ban \" + user)\n                break\n
\n\n

Thanks in advance!!

\n", "Lable": "No"} {"QuestionId": 36365425, "AnswerCount": 1, "Tags": "", "CreationDate": "2016-04-01T20:35:21.730", "AcceptedAnswerId": null, "Title": "Train convolutional neural network with theano/lasagne", "Body": "

I'm trying to implement a CNN using theano/lasagne. \nI've made a neural network but can't figure out how to train it with the current state.

\n\n

This is how I'm trying to get the output of the network with the current_states as input.

\n\n
train = theano.function([input_var], lasagne.layers.get_output(l.out))\noutput = train(current_states)\n
\n\n

However I get this error:

\n\n
theano.compile.function_module.UnusedInputError: theano.function was asked to create a function computing outputs given certain inputs, but the provided input variable at index 0 is not part of the computational graph needed to compute the outputs: inputs.\nTo make this error into a warning, you can pass the parameter on_unused_input='warn' to theano.function. To disable it completely, use on_unused_input='ignore'.\n
\n\n

Why is current_states not used?

\n\n

I want to get the output of the model on the current_states. How do I do this?

\n\n

(the CNN build code: http://pastebin.com/Gd35RncU)

\n", "Lable": "D"} {"QuestionId": 36388985, "AnswerCount": 1, "Tags": "", "CreationDate": "2016-04-03T17:54:51.387", "AcceptedAnswerId": "36393015", "Title": "How to print some debug?", "Body": "

I'm doing my first script with tensorflow.\nI wanted to try a simple Logistic regression to start, i'm working on kaggle titanic dataset.

\n\n

My problem is that i'm not able to print some tensor to debug things that i'm doing wrong.

\n\n

i read this post (How to print the value of a Tensor object in TensorFlow?) but i did not understand how i can print tensors. :(

\n\n

I'm pretty sure to be close but can't figure it out

\n\n

Let me show you what i am doing;

\n\n
train = pd.read_csv(\"./titanic_data/train.csv\", dtype={\"Age\": np.float64}, )\n\n# My parameters for start\ntrain_input = train[['Pclass','Age','SibSp','Parch','Fare']];\ntrain_label = train['Survived']\ntrain_label = train_label.reshape(891, 1)\n\n#split my dataset\ntest_input = train_input[800:891]\ntest_label = train_label[800:891]\ntrain_input = train_input[0:800]\ntrain_label = train_label[0:800]\n\nx = tf.placeholder(tf.float32, [None, 5]) #placeholder for input data\n\nW = tf.Variable(tf.zeros([5, 1])) #weight for softmax\n\nb = tf.Variable(tf.zeros([1])) # bias for softmax\n\ny = tf.nn.softmax(tf.matmul(x, W) + b) #our model -> pred from model\n\ny_ = tf.placeholder(tf.float32, [None, 1])#placeholder for input \n\ncross_entropy = -tf.reduce_sum(y_*tf.log(y)) # crossentropy cost function\n\ntrain_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)\ninit = tf.initialize_all_variables() # create variable\n\nsess = tf.InteractiveSession()\nsess.run(init)\n\ntestacc = []\ntrainacc = []\nfor i in range(15):\n    batch_xs = train_input[i*50:(i + 1) * 50]\n    batch_ys = train_label[i*50:(i + 1) * 50]\n\n    result = sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})\n    correct_prediction = tf.equal(y,y_)\n
\n\n

want to print here

\n\n
    **#correct_prediction.eval()\n#trying to print correct_prediction or y so i can see what is my model actualy doing**\n\n    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))\n    trainacc.append(sess.run(accuracy, feed_dict={x: train_input, y_: train_label}))\n    testacc.append(sess.run(accuracy, feed_dict={x: test_input, y_: test_label}))\n
\n\n

everything i'm doing is basics i guess. If somebody can help me i would be so great ! i'm kinda stuck and can't imporve my model. Don't hesitate to tell me good practice if you feel like :)

\n\n

Thanks for reading this !

\n", "Lable": "D"} {"QuestionId": 36410926, "AnswerCount": 1, "Tags": "", "CreationDate": "2016-04-04T19:10:24.427", "AcceptedAnswerId": "36443955", "Title": "Convolutional neural network: how to train it? (unsupervised)", "Body": "

I'm trying to implement a CNN to play a game. \nI'm using python with theano/lasagne. I've build the network and am now figuring out how to train it.

\n\n

So now I have a batch of 32 states and for each state in that batch the action and the expected rewards for that action.

\n\n

Now how can I train the network so that it learn that these actions in these states lead to these rewards?

\n\n

EDIT: Clarifying my problem.

\n\n

Here is my full code: http://pastebin.com/zY8w98Ng\nThe snake import: http://pastebin.com/fgGCabzR

\n\n

I'm having trouble with this bit:

\n\n
def _train(self):\n    # Prepare Theano variables for inputs and targets\n    input_var = T.tensor4('inputs')\n    target_var = T.ivector('targets')\n    states = T.tensor4('states')\n    print \"sampling mini batch...\"\n    # sample a mini_batch to train on\n    mini_batch = random.sample(self._observations, self.MINI_BATCH_SIZE)\n    # get the batch variables\n    previous_states = [d[self.OBS_LAST_STATE_INDEX] for d in mini_batch]\n    actions = [d[self.OBS_ACTION_INDEX] for d in mini_batch]\n    rewards = [d[self.OBS_REWARD_INDEX] for d in mini_batch]\n    current_states = np.array([d[self.OBS_CURRENT_STATE_INDEX] for d in mini_batch])\n    agents_expected_reward = []\n    # print np.rollaxis(current_states, 3, 1).shape\n    print \"compiling current states...\"\n    current_states = np.rollaxis(current_states, 3, 1)\n    current_states = theano.compile.sharedvalue.shared(current_states)\n\n    print \"getting network output from current states...\"\n    agents_reward_per_action = lasagne.layers.get_output(self._output_layer, current_states)\n\n\n    print \"rewards adding...\"\n    for i in range(len(mini_batch)):\n        if mini_batch[i][self.OBS_TERMINAL_INDEX]:\n            # this was a terminal frame so need so scale future reward...\n            agents_expected_reward.append(rewards[i])\n        else:\n            agents_expected_reward.append(\n                rewards[i] + self.FUTURE_REWARD_DISCOUNT * np.max(agents_reward_per_action[i].eval()))\n\n    # figure out how to train the model (self._output_layer) with previous_states,\n    # actions and agent_expected_rewards\n
\n\n

I want to update the model using previous_states, actions and agent_expected_rewards so that it learn that those actions lead to those rewards.

\n\n

I expect it might look something like this:

\n\n
train_model = theano.function(inputs=[input_var],\n    outputs=self._output_layer,\n    givens={\n        states: previous_states,\n        rewards: agents_expected_reward\n        expected_rewards: agents_expected_reward)\n
\n\n

I just don't get how the givens would effect the model because when building the network I don't specify them. I can't find it in the theano and lasagne documentation either.

\n\n

So how can I update the model/network so that it 'learns'.

\n\n

If its still not clear, comment on what information is still needed. I've been trying to figure this out for a few days now.

\n", "Lable": "D"} {"QuestionId": 36425107, "AnswerCount": 0, "Tags": "", "CreationDate": "2016-04-05T11:28:37.157", "AcceptedAnswerId": null, "Title": "Faster RCNN training get stuck in iteration 660", "Body": "

I met one problem where I trained py-faster-rcnn on my own dataset, but it get stuck in iteration 660 for a long time and no response. Has anyone met this problem before? How to solve it? Thanks a lot!

\n\n

FYR:

\n\n
\n
I0404 17:50:23.514286 25601 solver.cpp:571] Iteration 640, lr = 0.001\nI0404 17:50:24.876749 25601 solver.cpp:242] Iteration 660, loss = 0.341694\nI0404 17:50:24.876804 25601 solver.cpp:258] Train net output #0: rpn_cls_loss = 0.296529 (* 1 = 0.296529 loss)\nI0404 17:50:24.876819 25601 solver.cpp:258] Train net output #1: rpn_loss_bbox = 0.0451643 (* 1 = 0.0451643 loss)\nI0404 17:50:24.876835 25601 solver.cpp:571] Iteration 660, lr = 0.001\n
\n
\n", "Lable": "D"} {"QuestionId": 36484283, "AnswerCount": 1, "Tags": "", "CreationDate": "2016-04-07T18:23:25.207", "AcceptedAnswerId": "36505300", "Title": "How to do element-wise conditional indexing comparison in Theano?", "Body": "

The operation consists of two arrays X and idx of equal length where the values of idx can vary between 0 to (k-1) with the value of k given.

\n\n

This is the general Python code to illustrate this.

\n\n
import numpy as np\n\nX = np.arange(6) # Just for a sample of elements\nk = 3\nidx = numpy.array([[0, 1, 2, 2, 0, 1]]).T # Can only contain values in [0..(k-1)]\nnp.array([X[np.where(idx==i)[0]] for i in range(k)])\n
\n\n

Sample output:

\n\n
array([[0, 4],\n       [1, 5],\n       [2, 3]])\n
\n\n

Note that there is actually a reason for me to represent idx as a matrix and not as a vector. It was initialised to numpy.zeros((n,1)) as part of its computation, where n the size of X.

\n\n

I tried implement this in Theano like so

\n\n
import theano\nimport theano.tensor as T\n\nX = T.vector('X')\nidx = T.vector('idx')\nk = T.scalar()\nc = theano.scan(lambda i: X[T.where(T.eq(idx,i))], sequences=T.arange(k)) \nf = function([X,idx,k],c)\n
\n\n

But I received this error at line where c is defined:

\n\n
TypeError: Wrong number of inputs for Switch.make_node (got 1((<int8>,)), expected 3)\n
\n\n

Is there a simple way to implement this in Theano?

\n", "Lable": "D"} {"QuestionId": 36484695, "AnswerCount": 1, "Tags": "", "CreationDate": "2016-04-07T18:46:04.683", "AcceptedAnswerId": null, "Title": "How to make Theano use the integrated GPU in MacBook Air?", "Body": "

I tried running the test program for GPU usage:

\n\n
from theano import function, config, shared, tensor, sandbox\nimport numpy\nimport time\nvlen=10*30*768 #10x #coresx #threadspercore \niters = 1000\nrng = numpy.random.RandomState(22)\n\nx = shared(numpy.asarray(rng.rand(vlen), config.floatX)) \nf = function([], tensor.exp(x)) \nprint(f.maker.fgraph.toposort())\nt0 = time.time()\nfor i in xrange(iters): \n    r = f()\nt1 = time.time()\nprint(\"Looping %d times took %f seconds\" % (iters, t1 - t0)) \nprint(\"Result is %s\" % (r,))\nif numpy.any([isinstance(x.op, tensor.Elemwise) and ('Gpu' not in type(x.op).__name__) \n              for x in f.maker.fgraph.toposort()]): \n    print('Used the cpu')\nelse:\n    print('Used the gnu')\n
\n\n

It only shows this (even after installing libgpuarray):

\n\n
[Elemwise{exp,no_inplace}(<TensorType(float64, vector)>)]\nLooping 1000 times took 2.723539 seconds\nResult is [ 1.23178032  1.61879341  1.52278065 ...,  2.20771815  2.29967753\n  1.62323285]\nUsed the cpu\n
\n\n

I would like to know how to utilise the integrated GPU of MacBook Air (Early 2014).

\n\n

My processor has Intel HD Graphics 5000 -- not NVIDIA and hence not CUDA compatible Many links suggest usage of OpenCL. This was also supposed to be pre-installed with OS-X. But I can't make head or tail out of the links in the web.

\n\n

I could not find much help of how to set up Theano in the docs either.

\n\n

I just need to make Theano use my Mac's integrated GPU. Is this possible? If so, how? What are its prerequisites?

\n", "Lable": "D"}