当我有形状[2,2,2]的数据时,例如:
a = np.array([[(1,2), (3,4)],
[(5,6), (7,8)]
])
我希望图层输出[2,2],例如:
b = np.array([[1,0],
[0,1]])
如何构建图层?我当前的设置返回[2,2,1]的形状,我似乎无法在图层的单位变量中指定尺寸:
tf_x = tf.placeholder(tf.float32, [None, 2, 2])
output = tf.layers.dense(tf_x, 1, tf.nn.relu)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
pred = sess.run(output, {tf_x: a})
答案 0 :(得分:1)
您可以这样做:
b = tf.reshape(a, shape)
答案 1 :(得分:1)
我当前的设置返回[2,2,1]的形状,我似乎无法在图层的单位变量中指定尺寸:
#include<windows.h>
#include <GL/glut.h>
float yRot=0.0;
void Render()
{
//clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();//load identity matrix
glTranslatef(0.0f,0.0f,-4.0f);//move forward 4 units
//rotate along the y-axis
glRotatef(yRot,0.0f,1.0f,0.0f);
glColor3f(0.0f,0.0f,1.0f); //blue color
glBegin(GL_POLYGON);//begin drawing of polygon
glVertex3f(-0.5f,0.5f,0.0f);//first vertex
glVertex3f(0.5f,0.5f,0.0f);//second vertex
glVertex3f(1.0f,0.0f,0.0f);//third vertex
glVertex3f(0.5f,-0.5f,0.0f);//fourth vertex
glVertex3f(-0.5f,-0.5f,0.0f);//fifth vertex
glVertex3f(-1.0f,0.0f,0.0f);//sixth vertex
glEnd();//end drawing of polygon
yRot+=0.1f;//increment the yRot variable
}
//method the reshape the entire figure.
void reshape(int x, int h){
glViewport(0,0,x,h);
}
void init()
{
glClearColor(0.0,0.0,0.2,0.8);
}
int main(int argc, char** argv)
{
glutCreateWindow("simple triangles");
glutDisplayFunc(Render);
glutReshapeFunc(reshape);
init();
glutMainLoop();
}