我尝试使用这个代码中的整数编码作为一层,但是‘ValueError: None values not supported.’
liujiaxing1204 opened this issue · 0 comments
your code:
class VectorQuantizer(Layer):
def init(self, num_codes, **kwargs):
super(VectorQuantizer, self).init(**kwargs)
self.num_codes = num_codes
def build(self, input_shape):
super(VectorQuantizer, self).build(input_shape)
dim = input_shape[-1]
self.embeddings = self.add_weight(
name='embeddings',
shape=(self.num_codes, dim),
initializer='uniform')
def call(self, inputs):
"""inputs.shape=[None, m, m, dim]
"""
l2_inputs = K.sum(inputs**2, -1, keepdims=True)
l2_embeddings = K.sum(self.embeddings**2, -1)
for _ in range(K.ndim(inputs) - 1):
l2_embeddings = K.expand_dims(l2_embeddings, 0)
embeddings = K.transpose(self.embeddings)
dot = K.dot(inputs, embeddings)
distance = l2_inputs + l2_embeddings - 2 * dot
codes = K.cast(K.argmin(distance, -1), 'int32')
code_vecs = K.gather(self.embeddings, codes)
return code_vecs
def compute_output_shape(self, input_shape):
return input_shape
我的使用方法:model.add(VectorQuantizer(num_codes, name='vq'))
error:
Traceback (most recent call last):
File "vqlayer.py", line 114, in
validation_data=(x_test, y_test))
File "/opt18/tensorflow/lib/python2.7/site-packages/keras/models.py", line 965, in fit
validation_steps=validation_steps)
File "/opt18/tensorflow/lib/python2.7/site-packages/keras/engine/training.py", line 1646, in fit
self._make_train_function()
File "/opt18/tensorflow/lib/python2.7/site-packages/keras/engine/training.py", line 970, in _make_train_function
loss=self.total_loss)
File "/opt18/tensorflow/lib/python2.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/opt18/tensorflow/lib/python2.7/site-packages/keras/optimizers.py", line 455, in get_updates
m_t = (self.beta_1 * m) + (1. - self.beta_1) * g
File "/opt18/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 885, in binary_op_wrapper
y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")
File "/opt18/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 836, in convert_to_tensor
as_ref=False)
File "/opt18/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 926, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/opt18/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 229, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/opt18/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/constant_op.py", line 208, in constant
value, dtype=dtype, shape=shape, verify_shape=verify_shape))
File "/opt18/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/tensor_util.py", line 371, in make_tensor_proto
raise ValueError("None values not supported.")
ValueError: None values not supported.
gpu02
Done.