How to define/declare a list of struct in python? - list

I have the following code:
import os
test_list = [{"name" : "axi_rd_only_test", "seed" : 3}, {"name" : "axi_invalid_regs_test", "seed" : 5}]
os.popen("cd C:/raft/raftortwo/girobo2/ver/sim")
for test in test_list:
os.environ["MY_TEST_NAME"] = test.name
os.environ["MY_TEST_SEED"] = test.seed
os.system("vsim -c -do top_tb_simulate_reg.tcl")
I got the following errors:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\saritr\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "C:\Users\saritr\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 88, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "C:/Users/saritr/AppData/Local/Continuum/Anaconda3/lib/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 490, in <module>
#monkeypatch_method(pdb.Pdb, 'Pdb')
File "C:/Users/saritr/AppData/Local/Continuum/Anaconda3/lib/site-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 485, in decorator
% (cls.__name__, old_ref))
KeyError: 'SpyderPdb._old_Pdb_user_return already exists.'
Should I define the struct's list differently?

Related

How to create multiple Conv3DLSTMCell in tensorflow

I'm trying to create my model with several conv3d lstm cell layers:
I run the following code:
conv1, state1 = conv3d('conv1', _X, [8,112,112,1], [3,3,3], 64)
pool1 = max_pool('pool1', conv1, k=1)
conv2, state2 = conv3d('conv2', pool1, [8, 56, 56, 64], [3, 3, 3], 128)
pool2 = max_pool('pool2', conv2, k=2)
The conv3d functions:
def conv3d(myname, l_input, shape, kernel, outchan):
cell = contrib_rnn_cell.Conv3DLSTMCell(input_shape=shape, output_channels=out$
hidden = cell.zero_state(array_ops.shape(l_input)[0], dtypes.float32)
output, state = cell(l_input, hidden)
print(output.shape)
return output, state
My code runs OK for the conv1 and pool1 but for conv2 layer it shows me an error:
Traceback (most recent call last):
File "conv3dlstm.py", line 272, in <module>
run(16)
File "conv3dlstm.py", line 199, in run
biases)
File "/home/user/projects/model_conv3dlstm.py", line 47, in inference_c3d
conv2, state2 = conv3d('conv2', pool1, [8, 56, 56, 64], [3, 3, 3], 128)
File "/home/user/projects/model_conv3dlstm.py", line 32, in conv3d
output, state = cell(l_input, hidden)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn_cell_impl.py", line 190, in __call__
return super(RNNCell, self).__call__(inputs, state)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/layers/base.py", line 696, in __call__
outputs = self.call(inputs, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py", line 2110, in call
4 * self._output_channels, self._use_bias)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py", line 2200, in _conv
"kernel", filter_size + [total_arg_size_depth, num_features], dtype=dtype)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 1297, in get_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 1093, in get_variable
constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 431, in get_variable
return custom_getter(**custom_getter_kwargs)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn_cell_impl.py", line 193, in _rnn_get_variable
variable = getter(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 408, in _true_getter
use_resource=use_resource, constraint=constraint)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/variable_scope.py", line 747, in _get_single_variable
name, "".join(traceback.format_list(tb))))
ValueError: Variable conv_lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py", line 2200, in _conv
"kernel", filter_size + [total_arg_size_depth, num_features], dtype=dtype)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py", line 2110, in call
4 * self._output_channels, self._use_bias)
File "/home/user/projects/model_conv3dlstm.py", line 32, in conv3d
output, state = cell(l_input, hidden)
I saw the code in run_cell.py at line 2200 which is:
kernel = vs.get_variable(
"kernel", filter_size + [total_arg_size_depth, num_features], dtype=dtype)
Which is getting variable with fixed name "kernel". If I understand it correctly, it is supposed to be unique. But it means I can't create more of Conv3DLSTMCells than one? Is it a bug or am I using it incorrectly?

TypeError: 'NoneType' object is not subscriptable from call to integrate

Submitted issue https://github.com/sympy/sympy/issues/12993
Is this a bug? Why is this error generated?
>python
Python 3.6.1 |Anaconda custom (64-bit)| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy import *
>>> A,B,y=symbols('A B y')
>>> integrate(-(A**2+B**2*(-y**2+1))**(1/2)/(-y**2+1),y)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/integrals.py", line 1295, in integrate
risch=risch, manual=manual)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/integrals.py", line 486, in doit
conds=conds)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/integrals.py", line 919, in _eval_integral
result = manualintegrate(g, x)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 1223, in manualintegrate
return _manualintegrate(integral_steps(f, var))
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 1013, in integral_steps
fallback_rule)(integral)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 65, in null_safe_rl
result = rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 212, in _alternatives
result = rule(integral)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 33, in conditioned_rl
return rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 176, in _rewriter
substep = integral_steps(rewritten, symbol)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 1013, in integral_steps
fallback_rule)(integral)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 65, in null_safe_rl
result = rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 95, in switch_rl
return rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 65, in null_safe_rl
result = rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 335, in mul_rule
next_step = integral_steps(f, symbol)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 1013, in integral_steps
fallback_rule)(integral)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 85, in do_one_rl
result = rl(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/strategies/core.py", line 65, in null_safe_rl
result = rule(expr)
File "/home/me/anaconda3/lib/python3.6/site-packages/sympy/integrals/manualintegrate.py", line 743, in trig_substitution_rule
a = match[a]
TypeError: 'NoneType' object is not subscriptable
>>>
Interesting thing is that, if I issue the same command right again, the error do not show up
>>> integrate(-(A**2+B**2*(-y**2+1))**(1/2)/(-y**2+1),y)
Integral((A**2 - B**2*y**2 + B**2)**0.5/((y - 1)*(y + 1)), y)
It only shows up first time it is used! It looks like using it first time loads something to memory and hence next time the error do not show up.
Any idea what is going on?

TypeError: float() argument must be a string or a number, not 'map'

I am running a simple program from GitHub (https://github.com/tyleryasaka/weatherman).
It gives me this error:
Traceback (most recent call last):
File "C:/Users/Humxa/Desktop/weatherman-master/weatherman.py", line 39, in <module>
actual = learn.predict(classifier, trainings, tests)
File "C:\Users\Humxa\Desktop\weatherman-master\learn.py", line 11, in predict
fit = classifier.fit(data, target)
File "C:\Python34\lib\site-packages\sklearn\tree\tree.py", line 739, in fit
X_idx_sorted=X_idx_sorted)
File "C:\Python34\lib\site-packages\sklearn\tree\tree.py", line 122, in fit
X = check_array(X, dtype=DTYPE, accept_sparse="csc")
File "C:\Python34\lib\site-packages\sklearn\utils\validation.py", line 382, in check_array
array = np.array(array, dtype=dtype, order=order, copy=copy)
TypeError: float() argument must be a string or a number, not 'map'

Unable to load custom initializer from the saved model, passing custom_objects is not working

I saved model and weights in Keras and then try to load them ,but it shows that Invalid initialization: my_init.How can I fix the problem?
model = Sequential()
def my_init(shape, name=None):
return initializations.normal(shape, scale=0.1, name=name)
def m6_1():
model.add(Convolution2D(32, 3, 3, init=my_init))
model.add(Activation('relu'))
model.add(Convolution2D(32, 3, 3, init=my_init))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.5))
model.add(Flatten())
model.add(Dense(256, init=my_init))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))
save model and weights
model_json = model.to_json()
with open("model.json", "w") as json_file:
json_file.write(model_json)
model.save_weights("model.h5")
load model and weights
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json,custom_objects={'my_init':my_init})
loaded_model.load_weights("model.h5")
error messageTraceback (most recent call last):
File "revised_learn_ETL6_load_model.py", line 73, in <module>
loaded_model = model_from_json(loaded_model_json,custom_objects={"my_init": my_init})
File "/home/ubuntu/.env/local/lib/python2.7/site-packages/keras/models.py", line 197, in model_from_json
return layer_from_config(config, custom_objects=custom_objects)
File "/home/ubuntu/.env/local/lib/python2.7/site-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/home/ubuntu/.env/local/lib/python2.7/site-packages/keras/models.py", line 1019, in from_config
layer = get_or_create_layer(first_layer)
File "/home/ubuntu/.env/local/lib/python2.7/site-packages/keras/models.py", line 1003, in get_or_create_layer
layer = layer_from_config(layer_data)
File "/home/ubuntu/.env/local/lib/python2.7/site-packages/keras/utils/layer_utils.py", line 36, in layer_from_config
return layer_class.from_config(config['config'])
File "/home/ubuntu/.env/local/lib/python2.7/site-packages/keras/engine/topology.py", line 929, in from_config
return cls(**config)
File "/home/ubuntu/.env/local/lib/python2.7/site-packages/keras/layers/convolutional.py", line 381, in __init__
self.init = initializations.get(init, dim_ordering=dim_ordering)
File "/home/ubuntu/.env/local/lib/python2.7/site-packages/keras/initializations.py", line 107, in get
'initialization', kwargs=kwargs)
File "/home/ubuntu/.env/local/lib/python2.7/site-packages/keras/utils/generic_utils.py", line 16, in get_from_module
str(identifier))
Exception: Invalid initialization: my_init

On windows: Python editor cannot import mlab from mayavi, command prompt can

I'm new to Python, but I'm having some trouble using the mayavi package on Windows. I have installed Python(x,y) and I'm using the Sublime Text 2 and Spyder editor. So far I have found that running this code from the mayavi website:
from numpy import pi, sin, cos, mgrid
dphi, dtheta = pi/250.0, pi/250.0
[phi,theta] = mgrid[0:pi+dphi*1.5:dphi,0:2*pi+dtheta*1.5:dtheta]
m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;
r = sin(m0*phi)**m1 + cos(m2*phi)**m3 + sin(m4*theta)**m5 + cos(m6*theta)**m7
x = r*sin(phi)*cos(theta)
y = r*cos(phi)
z = r*sin(phi)*sin(theta)
# View it.
from mayavi import mlab
s = mlab.mesh(x, y, z)
mlab.show()
Results in the following error:
Traceback (most recent call last):
File "C:\Dropbox\...\test.py", line 23, in <module>
from mayavi import mlab
File "C:\Python27\lib\site-packages\mayavi\mlab.py", line 27, in <module>
from mayavi.tools.camera import view, roll, yaw, pitch, move
File "C:\Python27\lib\site-packages\mayavi\tools\camera.py", line 25, in <module>
from engine_manager import get_engine
File "C:\Python27\lib\site-packages\mayavi\tools\engine_manager.py", line 12, in <module>
from mayavi.preferences.api import preference_manager
File "C:\Python27\lib\site-packages\mayavi\preferences\api.py", line 4, in <module>
from preference_manager import preference_manager
File "C:\Python27\lib\site-packages\mayavi\preferences\preference_manager.py", line 29, in <module>
from traitsui.api import View, Group, Item
File "C:\Python27\lib\site-packages\traitsui\api.py", line 36, in <module>
from .editors.api import ArrayEditor
File "C:\Python27\lib\site-packages\traitsui\editors\__init__.py", line 23, in <module>
from .api import ArrayEditor
File "C:\Python27\lib\site-packages\traitsui\editors\api.py", line 24, in <module>
from .code_editor import CodeEditor
File "C:\Python27\lib\site-packages\traitsui\editors\code_editor.py", line 36, in <module>
class ToolkitEditorFactory ( EditorFactory ):
File "C:\Python27\lib\site-packages\traitsui\editors\code_editor.py", line 48, in ToolkitEditorFactory
mark_color = Color( 0xECE9D8 )
File "C:\Python27\lib\site-packages\traits\traits.py", line 489, in __call__
return self.maker_function( *args, **metadata )
File "C:\Python27\lib\site-packages\traits\traits.py", line 1203, in Color
return ColorTrait( *args, **metadata )
File "C:\Python27\lib\site-packages\traitsui\toolkit_traits.py", line 7, in ColorTrait
return toolkit().color_trait( *args, **traits )
File "C:\Python27\lib\site-packages\traitsui\toolkit.py", line 122, in toolkit
_toolkit = _import_toolkit( toolkit_name )
File "C:\Python27\lib\site-packages\traitsui\toolkit.py", line 51, in _import_toolkit
return __import__( name, globals=globals(), level=1 ).toolkit
File "C:\Python27\lib\site-packages\traitsui\wx\__init__.py", line 26, in <module>
import toolkit
File "C:\Python27\lib\site-packages\traitsui\wx\toolkit.py", line 61, in <module>
from helper \
File "C:\Python27\lib\site-packages\traitsui\wx\helper.py", line 43, in <module>
from pyface.timer.api \
File "C:\Python27\lib\site-packages\pyface\timer\api.py", line 17, in <module>
from .timer import Timer
File "C:\Python27\lib\site-packages\pyface\timer\timer.py", line 8, in <module>
from pyface.toolkit import toolkit_object
File "C:\Python27\lib\site-packages\pyface\toolkit.py", line 73, in <module>
_init_toolkit()
File "C:\Python27\lib\site-packages\pyface\toolkit.py", line 45, in _init_toolkit
be = import_toolkit(tk)
File "C:\Python27\lib\site-packages\pyface\toolkit.py", line 31, in import_toolkit
__import__(be + 'init')
File "C:\Python27\lib\site-packages\pyface\ui\qt4\init.py", line 18, in <module>
from pyface.qt import QtCore, QtGui, qt_api
File "C:\Python27\lib\site-packages\pyface\qt\__init__.py", line 33, in <module>
prepare_pyqt4()
File "C:\Python27\lib\site-packages\pyface\qt\__init__.py", line 17, in prepare_pyqt4
sip.setapi('QDate', 2)
ValueError: API 'QDate' has already been set to version 1
[Finished in 1.5s with exit code 1]
The weird thing is, when running the mayavi code directly in command prompt, it does work! So why do I get the error in both Sublime Text 2 and in Spyder?
Thank you for taking the time to look at my question
Edit: when importing numpy completely instead of the pi, sin, cos, and mgrid commands only: the error changes to:
Traceback (most recent call last):
File "C:\Dropbox\Mijn documenten\CiTG\CIE5 - MSc Thesis\Python_TopOpPy_Christopher\testy.py", line 24, in <module>
from mayavi import mlab
File "C:\Python27\lib\site-packages\mayavi\mlab.py", line 27, in <module>
from mayavi.tools.camera import view, roll, yaw, pitch, move
File "C:\Python27\lib\site-packages\mayavi\tools\camera.py", line 25, in <module>
from engine_manager import get_engine
File "C:\Python27\lib\site-packages\mayavi\tools\engine_manager.py", line 12, in <module>
from mayavi.preferences.api import preference_manager
File "C:\Python27\lib\site-packages\mayavi\preferences\api.py", line 4, in <module>
from preference_manager import preference_manager
File "C:\Python27\lib\site-packages\mayavi\preferences\preference_manager.py", line 29, in <module>
from traitsui.api import View, Group, Item
File "C:\Python27\lib\site-packages\traitsui\api.py", line 36, in <module>
from .editors.api import ArrayEditor
File "C:\Python27\lib\site-packages\traitsui\editors\__init__.py", line 23, in <module>
from .api import ArrayEditor
File "C:\Python27\lib\site-packages\traitsui\editors\api.py", line 24, in <module>
from .code_editor import CodeEditor
File "C:\Python27\lib\site-packages\traitsui\editors\code_editor.py", line 36, in <module>
class ToolkitEditorFactory ( EditorFactory ):
File "C:\Python27\lib\site-packages\traitsui\editors\code_editor.py", line 48, in ToolkitEditorFactory
mark_color = Color( 0xECE9D8 )
File "C:\Python27\lib\site-packages\traits\traits.py", line 489, in __call__
return self.maker_function( *args, **metadata )
File "C:\Python27\lib\site-packages\traits\traits.py", line 1203, in Color
return ColorTrait( *args, **metadata )
File "C:\Python27\lib\site-packages\traitsui\toolkit_traits.py", line 7, in ColorTrait
return toolkit().color_trait( *args, **traits )
File "C:\Python27\lib\site-packages\traitsui\toolkit.py", line 125, in toolkit
ETSConfig.toolkit = toolkit_name
File "C:\Python27\lib\site-packages\traits\etsconfig\etsconfig.py", line 213, in _set_toolkit
"already been set to %s" % (toolkit, self._toolkit)
ValueError: cannot set toolkit to wx because it has already been set to qt4
This makes the problem seem very similar to the one in this question. The solution there does not seem feasible for Sublime Text 2, however. And the Spyder solution does not work for me because the 'Enthought Tool Suite' option is greyed out. Any help is still appreciated!
For other running into the same problem, I have found the solution. What worked for me is including the following code:
from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4'
For example:
from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4' # Force PyQt4 utilization
import numpy
dphi, dtheta = numpy.pi/250.0, numpy.pi/250.0
[phi,theta] = numpy.mgrid[0:numpy.pi+dphi*1.5:dphi,0:2*numpy.pi+dtheta*1.5:dtheta]
m0 = 4; m1 = 3; m2 = 2; m3 = 3; m4 = 6; m5 = 2; m6 = 6; m7 = 4;
r = numpy.sin(m0*phi)**m1 + numpy.cos(m2*phi)**m3 + numpy.sin(m4*theta)**m5 + numpy.cos(m6*theta)**m7
x = r*numpy.sin(phi)*numpy.cos(theta)
y = r*numpy.cos(phi)
z = r*numpy.sin(phi)*numpy.sin(theta)
# View it.
from mayavi import mlab
s = mlab.mesh(x, y, z)
mlab.show()
gives the correct result.