I'm trying to run a minimization problem using scipy.optimize, including a NonlinearConstraint. I really don't want to code derivatives myself, so I'm using autograd to do it. But even though I follow the exact same procedure for the arguments to minimize and to NonlinearConstraint, the first seems to work and the second doesn't.
Here's my MWE:
useconstraint = False
import autograd
import autograd.numpy as np
from scipy import optimize
def function(x): return x[0]**2 + x[1]**2
functionjacobian = autograd.jacobian(function)
functionhvp = autograd.hessian_vector_product(function)
def constraint(x): return np.array([x[0]**2 - x[1]**2])
constraintjacobian = autograd.jacobian(constraint)
constrainthvp = autograd.hessian_vector_product(constraint)
constraint = optimize.NonlinearConstraint(constraint, 1, np.inf, constraintjacobian, constrainthvp)
startpoint = [1, 2]
bounds = optimize.Bounds([-np.inf, -np.inf], [np.inf, np.inf])
print optimize.minimize(
function,
startpoint,
method='trust-constr',
jac=functionjacobian,
hessp=functionhvp,
constraints=[constraint] if useconstraint else [],
bounds=bounds,
)
When I turn useconstraint off (at the top), it works fine and minimizes at (0, 0) as expected. When I turn it on, I get the following error:
Traceback (most recent call last):
File "test.py", line 29, in <module>
bounds=bounds,
File "/home/heshy/.local/lib/python2.7/site-packages/scipy/optimize/_minimize.py", line 613, in minimize
callback=callback, **options)
File "/home/heshy/.local/lib/python2.7/site-packages/scipy/optimize/_trustregion_constr/minimize_trustregion_constr.py", line 336, in _minimize_trustregion_constr
for c in constraints]
File "/home/heshy/.local/lib/python2.7/site-packages/scipy/optimize/_constraints.py", line 213, in __init__
finite_diff_bounds, sparse_jacobian)
File "/home/heshy/.local/lib/python2.7/site-packages/scipy/optimize/_differentiable_functions.py", line 343, in __init__
self.H = hess(self.x, self.v)
File "/home/heshy/.local/lib/python2.7/site-packages/autograd/wrap_util.py", line 20, in nary_f
return unary_operator(unary_f, x, *nary_op_args, **nary_op_kwargs)
File "/home/heshy/.local/lib/python2.7/site-packages/autograd/differential_operators.py", line 24, in grad
vjp, ans = _make_vjp(fun, x)
File "/home/heshy/.local/lib/python2.7/site-packages/autograd/core.py", line 10, in make_vjp
end_value, end_node = trace(start_node, fun, x)
File "/home/heshy/.local/lib/python2.7/site-packages/autograd/tracer.py", line 10, in trace
end_box = fun(start_box)
File "/home/heshy/.local/lib/python2.7/site-packages/autograd/wrap_util.py", line 15, in unary_f
return fun(*subargs, **kwargs)
File "/home/heshy/.local/lib/python2.7/site-packages/autograd/differential_operators.py", line 88, in vector_dot_grad
return np.tensordot(fun_grad(*args, **kwargs), vector, np.ndim(vector))
File "/home/heshy/.local/lib/python2.7/site-packages/autograd/tracer.py", line 44, in f_wrapped
ans = f_wrapped(*argvals, **kwargs)
File "/home/heshy/.local/lib/python2.7/site-packages/autograd/tracer.py", line 48, in f_wrapped
return f_raw(*args, **kwargs)
File "/home/heshy/.local/lib/python2.7/site-packages/numpy/core/numeric.py", line 1371, in tensordot
raise ValueError("shape-mismatch for sum")
ValueError: shape-mismatch for sum
What am I doing wrong? I think the issue is in the hessian_vector_product because I see hess in the error message, but I'm not sure about that.
Ok, I found the answer. This was very confusing.
The hessp argument to minimize expects a function that returns the "Hessian of objective function times an arbitrary vector p" (source). By contrast, the hess argument to NonlinearConstraint expects "A callable [that] must return the Hessian matrix of dot(fun, v)" (source).
If you interpret the first quote like I did, "Hessian of (objective function times an arbitrary vector p)", it means pretty much the same thing as "Hessian matrix of dot(fun, v)". I therefore assumed you could use the same autograd function for both.
However, the correct interpretation is "(Hessian of objective function) times an arbitrary vector p", which is completely different. The hessian_vector_product function in autograd gives the correct result for the first, but you need a different function for the second.
I'm facing trouble when training a model using pre-trained inceptionV3 for my own image data set.
I'm loading images using data.Dataset loader and 'transforms' for image transformation.
Here's my inceptionV3 model
inceptionV3 = torchvision.models.inception_v3(pretrained=True)
pretrained_model = nn.Sequential(*list(inceptionV3.children()))
pretrained_model = nn.Sequential(*list(pretrained_features.children())[:-1])
for param in pretrained_model.parameters(): param.requires_grad = False
Here's my transforms code
data_transforms = transforms.Compose([
transforms.Scale((299,299)),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
I'm getting this error at the line 'out_features = pretrained_model(inputs)'
Traceback (most recent call last): File "build_models.py", line 42, in <module> use_gpu=use_gpu)
File "/home/ubuntu/apparel-styles/ml_src/classifiers.py", line 488, in create_attributes_model batch_size, num_workers, num_epochs, use_gpu=use_gpu)
File "/home/ubuntu/apparel-styles/ml_src/classifiers.py", line 276, in train_model flatten_pretrained_out=flatten_pretrained_out)
File "/home/ubuntu/apparel-styles/ml_src/classifiers.py", line 181, in train_attribute_model out_features = pretrained_model(inputs)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__ result = self.forward(*input, **kwargs)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 68, in forward outputs = self.parallel_apply(replicas, inputs, kwargs)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/parallel/data_parallel.py", line 78, in parallel_apply return parallel_apply(replicas, inputs, kwargs, self.device_ids[:len(replicas)])
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 67, in parallel_apply raise output
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/parallel/parallel_apply.py", line 42, in _worker output = module(*input, **kwargs)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__ result = self.forward(*input, **kwargs)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/modules/container.py", line 67, in forward input = module(input)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__ result = self.forward(*input, **kwargs)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torchvision/models/inception.py", line 312, in forward x = self.fc(x)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__ result = self.forward(*input, **kwargs)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 55, in forward return F.linear(input, self.weight, self.bias)
File "/home/ubuntu/apparel-styles/env/venv/lib/python3.6/site-packages/torch/nn/functional.py", line 835, in linear return torch.addmm(bias, input, weight.t()) RuntimeError: size mismatch at /pytorch/torch/lib/THC/generic/THCTensorMathBlas.cu:243
After getting this error, I tried to print the input size. It's value is
print(inputs.shape)
torch.Size([256, 3, 299, 299])
I want to get information from a snmp device which is configured with auth protocol MD5 and priv protocol 3DES.
The configuration statement is
snmp-server user testuser testgroup v3 auth md5 authmd5pwd priv 3des privpwddes
The pysnmp code to access the device is
from pysnmp.hlapi import *
def get(mib):
errorIndication, errorStatus, errorIndex, varBinds = next(
getCmd(SnmpEngine(),
UsmUserData('nmsuser', 'authmd5pwd', 'privpwddes',
authProtocol=usmHMACMD5AuthProtocol,
privProtocol=usm3DESEDEPrivProtocol),
UdpTransportTarget(('10.96.158.251', 161)),
ContextData(),
ObjectType(ObjectIdentity(mib)))
)
if errorIndication:
print(errorIndication)
elif errorStatus:
print('%s at %s' % (errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
for varBind in varBinds:
print(varBind[1])
if __name__ == "__main__":
get('.1.3.6.1.2.1.1.5.0')
When I execute this I get
Traceback (most recent call last):
File "pytest.py", line 24, in
get('.1.3.6.1.2.1.1.5.0')
File "pytest.py", line 11, in get
ObjectType(ObjectIdentity(mib)))
File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 113, in getCmd
File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/carrier/asyncore/dispatch.py", line 50, in runDispatcher
pysnmp.error.PySnmpError: poll error: Traceback (most recent call last):
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/carrier/asyncore/dispatch.py", line 46, in runDispatcher
use_poll=True, map=self.__sockMap, count=1)
; File "/usr/lib/python2.7/asyncore.py", line 220, in loop
poll_fun(timeout, map)
; File "/usr/lib/python2.7/asyncore.py", line 201, in poll2
readwrite(obj, flags)
; File "/usr/lib/python2.7/asyncore.py", line 123, in readwrite
obj.handle_error()
; File "/usr/lib/python2.7/asyncore.py", line 108, in readwrite
obj.handle_read_event()
; File "/usr/lib/python2.7/asyncore.py", line 449, in handle_read_event
self.handle_read()
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/carrier/asyncore/dgram/base.py", line 163, in handle_read
self._cbFun(self, transportAddress, incomingMessage)
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/carrier/base.py", line 70, in _cbFun
self, transportDomain, transportAddress, incomingMessage
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/entity/engine.py", line 152, in __receiveMessageCbFun
self, transportDomain, transportAddress, wholeMsg
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/proto/rfc3412.py", line 344, in receiveMessage
statusInformation
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/proto/rfc3412.py", line 533, in __expireRequest
cachedParams['cbCtx'])
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/entity/rfc3413/cmdgen.py", line 104, in processResponsePdu
(origSendRequestHandle, cbFun, cbCtx))
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/proto/rfc3412.py", line 153, in sendPdu
pduVersion, PDU, expectResponse, sendPduHandle
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/proto/mpmod/rfc3412.py", line 240, in prepareOutgoingMessage
securityEngineId, securityName, securityLevel, scopedPDU
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/proto/secmod/rfc3414/service.py", line 525, in generateRequestMsg
None)
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/proto/secmod/rfc3414/service.py", line 395, in __generateRequestOrResponseMsg
(snmpEngineBoots, snmpEngineTime, None), dataToEncrypt
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/proto/secmod/eso/priv/des3.py", line 117, in encryptData
encryptKey, snmpEngineBoots
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/proto/secmod/eso/priv/des3.py", line 77, in __getEncryptionKey
preIV = privKey[24:32]
; File "/usr/local/lib/python2.7/dist-packages/pyasn1/type/univ.py", line 996, in __getitem__
return self.clone(self._value[i])
; File "/usr/local/lib/python2.7/dist-packages/pysnmp-4.4.3-py2.7.egg/pysnmp/proto/rfc1902.py", line 202, in clone
return univ.OctetString.clone(self, *args, **kwargs).setFixedLength(self.getFixedLength())
; File "/usr/local/lib/python2.7/dist-packages/pyasn1/type/base.py", line 349, in clone
return self.__class__(value, **initilaizers)
; File "/usr/local/lib/python2.7/dist-packages/pyasn1/type/univ.py", line 819, in __init__
base.AbstractSimpleAsn1Item.__init__(self, value, **kwargs)
; File "/usr/local/lib/python2.7/dist-packages/pyasn1/type/base.py", line 246, in __init__
raise exType('%s at %s' % (exValue, self.__class__.__name__))
;ValueConstraintError: , > failed at: ValueConstraintError(" failed at: ValueConstraintError('',)",) at OctetString
Seems to be a bug in pysnmp 4.4.3 when using 3DES with short-hash HMAC such as MD5.
You can either use some other AUTH algorithm which produces at least 32-octet long hash or pull fixed pysnmp (4.4.4) from its master branch.
Your script seems to work with the simulator once you change username/passphrase.
when I run a source code file of a software, a error raised.
Traceback (most recent call last):
File "gwava_annotate.py", line 297, in <module>
df = annotate(vf)
File "gwava_annotate.py", line 255, in annotate
encode_feats(vf, ENCODE_FEATS),
File "gwava_annotate.py", line 41, in encode_feats
for entry in annots:
File "pybedtools/cbedtools.pyx", line 787, in pybedtools.cbedtools.IntervalIterator.__next__ (pybedtools/cbedtools.cxx:11123)
File "pybedtools/cbedtools.pyx", line 652, in pybedtools.cbedtools.create_interval_from_list (pybedtools/cbedtools.cxx:9208)
IndexError: list index out of range
So I run the source code one by one till the error happened again.
>>> for entry in annots:
... fs = entry[4].strip(',').split(',')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pybedtools/cbedtools.pyx", line 787, in pybedtools.cbedtools.IntervalIterator.__next__ (pybedtools/cbedtools.cxx:11123)
File "pybedtools/cbedtools.pyx", line 652, in pybedtools.cbedtools.create_interval_from_list (pybedtools/cbedtools.cxx:9208)
IndexError: list index out of range
annots is a instance, you can see
>>> type(annots)
<class 'pybedtools.bedtool.BedTool'>
I tried to print it
>>> print(annots)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pybedtools/bedtool.py", line 1072, in __str__
for i in iter(self):
File "pybedtools/cbedtools.pyx", line 787, in pybedtools.cbedtools.IntervalIterator.__next__ (pybedtools/cbedtools.cxx:11123)
File "pybedtools/cbedtools.pyx", line 652, in pybedtools.cbedtools.create_interval_from_list (pybedtools/cbedtools.cxx:9208)
IndexError: list index out of range
And
>>> len(annots)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pybedtools/bedtool.py", line 1080, in __len__
return self.count()
File "/usr/local/lib/python2.7/dist-packages/pybedtools/bedtool.py", line 2283, in count
return sum(1 for _ in iter(self))
File "/usr/local/lib/python2.7/dist-packages/pybedtools/bedtool.py", line 2283, in <genexpr>
return sum(1 for _ in iter(self))
File "pybedtools/cbedtools.pyx", line 787, in pybedtools.cbedtools.IntervalIterator.__next__ (pybedtools/cbedtools.cxx:11123)
File "pybedtools/cbedtools.pyx", line 652, in pybedtools.cbedtools.create_interval_from_list (pybedtools/cbedtools.cxx:9208)
IndexError: list index out of range
So I check its attributes
>>> dir('annots')
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
So, I put annots content to a string
>>> a = ['DNase:26039,H3K4me3:13995,POLR2A:9215,H3K4me2:8024,H3K9ac:6869,H3K27ac:5904,H3K27me3:4816,H3K4me1:4622,FAIRE:4462,H2AFZ:3052,CTCF:2356,H3K36me3:1766,H3K79me2:1469,TAF1:1264,TBP:798,YY1:689,NFKB1:664,MYC:578,MAX:565,USF1:496,SP1:415,HEY1:409,SIN3A:405,ELF1:396,EP300:383,E2F1:377,H4K20me1:369,JUND:330,E2F6:315,EGR1:299,CEBPB:279,PAX5:251,CHD2:227,FOXA1:227,RAD21:218,TCF12:206,E2F4:205,STAT3:202,REST:200,GABPA:197,USF2:197,POU2F2:194,SLC22A2:194,TCF7L2:193,MXI1:183,NR3C1:180,HNF4A:177,GTF2F1:174,GATA1:169,EBF1:167,SPI1:167,HDAC2:163,TRIM28:154,CCNT2:149,HMGN3:141,GATA2:132,FOSL2:130,FOS:129,IRF4:116,ZNF263:116,TFAP2C:115,POLR2A_elongating:114,STAT1:109,RFX5:108,NRF1:107,H3K9me3:99,POLR3A:98,BCLAF1:97,FOXA2:97,IRF1:97,ELK4:87,HNF4G:87,SMC3:87,TFAP2A:87,ZBTB7A:75,TAF7:73,SRF:72,ZEB1:70,ETS1:69,JUN:66,BCL3:64,BRCA1:64,NR2C2:64,SMARCB1:64,BATF:60,GTF2B:58,MEF2A:57,SREBF1:56,TAL1:55,RXRA:54,NFYA:49,HSF1:47,BHLHE40:46,PBX3:44,NFYB:42,RDBP:42,SIX5:42,STAT2:39,ZNF143:38,ATF3:36,MAFK:34,IRF3:31,ZBTB33:29,SETDB1:24,CTCFL:23,SP2:23,SREBF2:21,CTBP2:16,GATA3:16,MEF2_complex:15,NFE2:15,SMARCC1:15,SUZ12:15,JUNB:14,SMARCA4:14,BDP1:13,ERALPHAA:10,FOSL1:10,H3K9me1:10,SIRT6:10,MAFF:9,NANOG:8,SMARCC2:8,BCL11A:4,BRF2:4,PPARGC1A:4,THAP1:4,Eralphaa:2,NR4A1:2,ESRRA:1,FAM48A:1,GTF3C2:1,POU5F1:1,PRDM1:1,ZNF274:1']
it worked
>>> for test in a:
... test1 = test[4].strip(',').split(',')
... print(test1)
['e']
>>> for test in a:
... b = test.strip(',').split(',')
...
>>> b
['DNase:26039', 'H3K4me3:13995', 'POLR2A:9215', 'H3K4me2:8024', 'H3K9ac:6869', 'H3K27ac:5904', 'H3K27me3:4816', 'H3K4me1:4622', 'FAIRE:4462', 'H2AFZ:3052', 'CTCF:2356', 'H3K36me3:1766', 'H3K79me2:1469', 'TAF1:1264', 'TBP:798', 'YY1:689', 'NFKB1:664', 'MYC:578', 'MAX:565', 'USF1:496', 'SP1:415', 'HEY1:409', 'SIN3A:405', 'ELF1:396', 'EP300:383', 'E2F1:377', 'H4K20me1:369', 'JUND:330', 'E2F6:315', 'EGR1:299', 'CEBPB:279', 'PAX5:251', 'CHD2:227', 'FOXA1:227', 'RAD21:218', 'TCF12:206', 'E2F4:205', 'STAT3:202', 'REST:200', 'GABPA:197', 'USF2:197', 'POU2F2:194', 'SLC22A2:194', 'TCF7L2:193', 'MXI1:183', 'NR3C1:180', 'HNF4A:177', 'GTF2F1:174', 'GATA1:169', 'EBF1:167', 'SPI1:167', 'HDAC2:163', 'TRIM28:154', 'CCNT2:149', 'HMGN3:141', 'GATA2:132', 'FOSL2:130', 'FOS:129', 'IRF4:116', 'ZNF263:116', 'TFAP2C:115', 'POLR2A_elongating:114', 'STAT1:109', 'RFX5:108', 'NRF1:107', 'H3K9me3:99', 'POLR3A:98', 'BCLAF1:97', 'FOXA2:97', 'IRF1:97', 'ELK4:87', 'HNF4G:87', 'SMC3:87', 'TFAP2A:87', 'ZBTB7A:75', 'TAF7:73', 'SRF:72', 'ZEB1:70', 'ETS1:69', 'JUN:66', 'BCL3:64', 'BRCA1:64', 'NR2C2:64', 'SMARCB1:64', 'BATF:60', 'GTF2B:58', 'MEF2A:57', 'SREBF1:56', 'TAL1:55', 'RXRA:54', 'NFYA:49', 'HSF1:47', 'BHLHE40:46', 'PBX3:44', 'NFYB:42', 'RDBP:42', 'SIX5:42', 'STAT2:39', 'ZNF143:38', 'ATF3:36', 'MAFK:34', 'IRF3:31', 'ZBTB33:29', 'SETDB1:24', 'CTCFL:23', 'SP2:23', 'SREBF2:21', 'CTBP2:16', 'GATA3:16', 'MEF2_complex:15', 'NFE2:15', 'SMARCC1:15', 'SUZ12:15', 'JUNB:14', 'SMARCA4:14', 'BDP1:13', 'ERALPHAA:10', 'FOSL1:10', 'H3K9me1:10', 'SIRT6:10', 'MAFF:9', 'NANOG:8', 'SMARCC2:8', 'BCL11A:4', 'BRF2:4', 'PPARGC1A:4', 'THAP1:4', 'Eralphaa:2', 'NR4A1:2', 'ESRRA:1', 'FAM48A:1', 'GTF3C2:1', 'POU5F1:1', 'PRDM1:1', 'ZNF274:1']
How can I fix this problem?
The software introduced by a Nature Method paper, and I do not change any code.Somebody has used it(I know from the paper's cite), but it stops here when I run.
There are many question aboud "list index out of range", but I can not get useful information.
I contacted with somebody maintain the pybedtools, and he told me that it was the BedTools version make this error happen. I should change it to developer version.
Is it possible in keras to use tensorflow tensor manipulations commands for altering the shape of data, of split by an axis or somethign like that..
I am currently trying something like this:
def row_convolution(input):
filter_size = 8
temp_list = []
input = tf.placeholder(tf.float32,shape=(None,33,1,8,45,3))
for section in tf.unstack(input,axis=1):
section = tf.reshape(section,[1,8,45,3])
temp_list.append((Conv2D(filters = 1, kernel_size = (8,45), activation='relu' , name = 'conv')(section)))
print "len: " + str(len(temp_list))
return tf.convert_to_tensor(np.array(temp_list))
Which is is the function for a lamdba layer, but the last command give me an error message stating:
Traceback (most recent call last):
File "keras_cnn_phoneme_original_fit_generator.py", line 182, in <module>
fws()
File "keras_cnn_phoneme_original_fit_generator.py", line 167, in fws
model.add(Lambda(row_convolution,input_shape = (33,1,8,45,3)))
File "/usr/local/lib/python2.7/dist-packages/keras/models.py", line 422, in add
layer(x)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 554, in __call__
output = self.call(inputs, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 659, in call
return self.function(inputs, **arguments)
File "keras_cnn_phoneme_original_fit_generator.py", line 147, in row_convolution
return tf.convert_to_tensor(np.array(temp_list))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 637, in convert_to_tensor
as_ref=False)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 702, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 110, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/constant_op.py", line 99, in constant
tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 451, in make_tensor_proto
append_fn(tensor_proto, proto_values)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.py", line 109, in SlowAppendObjectArrayToTensorProto
tensor_proto.string_val.extend([compat.as_bytes(x) for x in proto_values])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/util/compat.py", line 65, in as_bytes
(bytes_or_text,))
TypeError: Expected binary or unicode string, got <tf.Tensor 'lambda_1/conv/Relu:0' shape=(1, 1, 1, 1) dtype=float32>