h2o tensorflow deep learning demo fails - python-2.7

I watched the video demo
http://www.lectoro.com/index.php?action=search&ytq=H2O%20TensorFlow%20Deep%20Learning%20Demo
I am able to set up the env using the same spark and sparkling-water versions. The tensorflow runs on python3. Apparently, the example uses python2 code. I am getting SyntaxError: Missing parentheses in call to 'print'. It points to a file with an extreme long path starting with /private ends in context.py.
Is there a way I can get this demo to work with my python3 environment?

yes, right now demo is Python 2 specific. However, we will update it to match Python 3 syntax. I meantime feel free to modify code or look at DeepWater which introduces Deep Learning on top of MxNet (and TF, and Caffe - in progress) https://github.com/h2oai/deepwater

Assuming you are using this python notebook: https://github.com/h2oai/sparkling-water/blob/master/py/examples/notebooks/TensorFlowDeepLearning.ipynb
The changes for Python 3:
In [8] put parantheses around:
print( [c.dim for c in H2O_w] )
print( [c.dim for c in H2O_b] )
In [3] add a list() around the use of range():
sc.parallelize(list(range(NODES)), NODES).map(map_fun).collect()
And [4]:
self._x = list( range(784) )
(I notice this change had already been done in the call to train().)
I couldn't spot anything else, and those changes should be compatible with Python 2. If you still get errors can you post in which section of the notebook that the error happens in?

Related

Can't find pvlib.pvsystem.Array

I am using pvlib-python to model a series of photovoltaic installations.
I have been running the normal pvlib-python procedural code just fine (as described in the intro tutorial.
I am now trying to extend my model to be able to cope with several arrays of panels in different directions etc, but connected to the same inverter. For this I though the easiest way would be to use pvlib.pvsystem.Array to create a list of Array-objects that I can then pass to the pvlib.pvsytem.PVSystem class (as described here).
My issue now is that I can't find pvsystem.Array at all? eg I'm just getting:
AttributeError: module 'pvlib.pvsystem' has no attribute 'Array'
when I try to create an instance of Array using:
from pvlib import pvsystem
module_parameters = {'pdc0': 5000, 'gamma_pdc': -0.004}
array_one = pvsystem.Array(module_parameters=module_parameters)
array_two = pvsystem.Array(module_parameters=module_parameters)
system_two_arrays = pvsystem.PVSystem(arrays=[array_one, array_two],
inverter_parameters=inverter_parameters)
as described in the examples in the PVSystem and Arrays page.
I am using pvlib-python=0.8.1, installed in my conda env using conda install -c conda-forge pvlib-python.
I am quite confused about this since I can obviously see all the documentation on pvsystem.Array on read-the-docs and see the source code on pvlib's github.
When I look at the code in my conda env it doesn't have Array under pvsystem (or if I list it using dir(pvlib.pvsystem)), so it is something wrong with the installation, but I simply can't figure out what. I've tried installing pvlib again and using different installation but always the same issue.
Am I missing something really obvious here?
Kind regards and thank you,
This feature is not present in the current stable version (8.1). If you want to use it already you could download the latest source as a zip file and install it, or clone the pvlib git repository on your computer.

Code conversion from python 2 to python 3

I'm setting up a new algorithm which combines an object detector(bounding box detector) which is in python 3 and a mask generator which is in python 2. The problem here is I have several python 2 files which is required for the mask generation algorithm. So I tried 2to3 to convert all my python 2 files to python 3. The script seemed like working but as it was a deep learning algorithm(for mask generation when bounding box coordinates are given as input) which needs some pytorch weights to be loaded, while testing the model in python 3 the program was throwing out error like
"RuntimeError: Expected object of type torch.FloatTensor but found
type torch.cuda.FloatTensor for argument #2 ‘weight’"
I have searched in PyTorch forums but none of the posts were useful to me. Is it because my mask generation code is trained in python 2 ?
Does that means while loading the weights and testing the model I should use python 2 not python 3 ? It would be great if someone can shed some light on this. As a work around I can still use the object detector code downgraded to python 2. But still I want to know why it was throwing the error.
The problem is(can) that cpu object is expected but it gpu object. Try to put the object to cpu:
mask.cpu()
I just resolved the issue by re-installing the torch(0.4.0) and torchvision(0.2.1) for my conda environment. I had to downgrade the versions of both of them. Finally I was successful in converting my python 2.7 code to python 3. Thanks to 2to3 library. Actually this error was happening in the image normalize function of the PyTorch. That was an internal function which accepts the image array as tensors.
tensor.sub_(mean[:, None, None]).div_(std[:, None, None])
RuntimeError: expected type torch.cuda.FloatTensor but got torch.FloatTensor

Running Python programs in python.exe, the command prompt, and IDLE

Let me preface this post that I am incredibly new to python. I took a course in codeacademy but haven't actually used python on my own computer until now. Let me also explain to everyone that my coding experience is limited to VBA and excel. I have very little knowledge of how to use the command prompt, how libraries work, etc, etc.
I'm having some issues. I've changed my directory to recognize python when I type python in my command prompt. Then I can do simple things like
print "hello"
however if i write something like this
def firstfunction(t):
print t+5
return
firstfunction(5)
I would expect this to print the number 10, however I get the following error:
File"stdin", line 4
first function(5)
^
syntaxerror: invalid syntax
However if I use this in IDLE and run it it works fine.
Next I've saved some python programs I wrote. One I saved as Hello.py
i want to run this code from my python exe or from the command prompt but can't figure out how.
Please any answers helpful, if you use computer lingo, try and keep it as simple as possible. I'm super new!
Thanks
If the location of python is not included in your path, add it. But in any case, you should be able to run this successfully from the directory containing your python.exe.
e.g, if python lives in C:\Python27:
cd C:\Python27
python mypythonscript.py

Enthought Canopy User Input

I'm using Enthought Canopy on Mac OSX Lion. I'm using this because of the ease at which modules and libraries can be downloaded and installed (had a lot of trouble downloading pandas and numpy through terminal due to a number of issues).
So, now I'm doing my coding for a project in Canopy, which is OK (still prefer Wing, though). The problem I have encountered is that I need to ask the user for input. When I do, for instance:
x = input('Enter your input here: ')
I get an EOF error as follows: EOFError: EOF when reading a line
I was looking around and believe that this may be something which Canopy does not support. Was wondering if this is, indeed, the case and if there is a solution/workaround to this problem?
I assume that you are entering this code in the IPython shell that is embedded in the Canopy editor. This is an upstream bug/deficiency in IPython's Qt console. Because the remote shell is not actually hooked up to a terminal, functions like input() and raw_input() need to be replaced to get the input from the GUI console widget instead. IPython (and thus Canopy) does replace raw_input() but does not replace input(). This code will work using Canopy's Python interpreter if you were to put it into a script and execute it from the command line, and it would also work in a terminal instance of IPython. It was most likely overlooked because it is usually considered a bad idea to use input().
Please use raw_input() instead and parse the string that you get. You can use eval() if you must, but I do recommend using a more specific parsing/conversion function.

Embedding IPython-shell in C/C++-program

I have a C++-program that allows me to run Python-scripts that C++ passes data to. If the Python-script fails the C++-program calls PyRun_InteractiveLoop to allow investigating the problem on an interactive shell. This works alright but I thought "Would be cool if IPython is installed I could use it in that case".
Now my problem is: all I find when looking for "ipython embedding" is instructions how to embed IPython into Python-programs (amongst others http://ipython.org/ipython-doc/dev/interactive/reference.html#embedding-ipython). I tried to reproduce these on the embedded regular python-shell I have but most of them fail in some way (usually because of a missing sys.argv .... that one I can solve).
Any suggestions how to do this? My first plan would have been to first import IPython via the C-API (that one I got covered). If that fails use the "regular" shell. Otherwise call IPython.embed() (or similar) via PyRun_InteractiveOneFlags
Have you considered using python debugger
>>> import pdb
>>> import yourmodule
>>> pdb.run('yourmodule.test()')