Tensorflow: создать вектор на основе входных данных - PullRequest
0 голосов
/ 10 июня 2019

Я не очень разбираюсь в Tensorflow, и я делаю одну из тех вещей, которые, по-видимому, были бы очень простыми, но я застрял в этом.,Вот что я получил:

def createTransformationMatrix(args):
    scale = args[0]
    M = tf.Variable([scale[0], 0, 0, 0, scale[1], 0, 0, 0], dtype=tf.float32)
    return  M

scaleValue = Input(shape=(2,));
createTransfMatrix = Lambda(createTransformationMatrix)(scaleValue)
transformImage = Model([scaleValue], createTransfMatrix, name='transformImage');
scaleValueInput = np.array([1.0,1.0])
output = transformImage.predict(scaleValueInput[None,:])

Это дает ошибку:

InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'lambda_1/Placeholder' with dtype float and shape [?,2]
     [[Node: lambda_1/Placeholder = Placeholder[dtype=DT_FLOAT, shape=[?,2], _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

1 Ответ

1 голос
/ 10 июня 2019

Вы можете сделать это с помощью tenorflow

scaleValue = tf.placeholder("float32", 2)
b = tf.expand_dims(scaleValue, axis=1)
c = tf.constant([[1,0,0,0]], 'float32')
d = tf.matmul(b,c)
res = tf.reshape(d, shape=[-1])

with tf.Session() as sess:
    print (sess.run([res], feed_dict={scaleValue: np.array([1,3])}))

выход

[array([1., 0., 0., 0., 3., 0., 0., 0.], dtype=float32)]


Решение с использованием заполнения

scaleValue = tf.placeholder("float32", 2)
a = tf.expand_dims(scaleValue, axis=1)
paddings = tf.constant([[0, 0,], [0, 3]])
b = tf.pad(a, paddings, "CONSTANT")
res = tf.reshape(b, shape=[-1])


with tf.Session() as sess:
    print (sess.run([res], feed_dict={scaleValue: np.array([1,3])}))

Установите постоянный отступ в нужную форму

Где в paddings = tf.constant([[top, bottom,], [left, right]]), top, bottom, left, right представляет №: нулей в соответствующей позиции.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...