예제 #1
0
파일: tf_test.py 프로젝트: linklab/aiclass
# g= graph.Graph()
g = tfg.Graph()
g.initialize()

# Create variables
a = tfg.Variable(5.0, name='a')
b = tfg.Variable(1.0, name='b')

# Create placeholder
x = tfg.Placeholder(name='x')

# Create hidden node y
y = tfg.Mul(a, x, name="y")

# Create output node z
z = tfg.Add(y, b, name="z")

#nx.draw_networkx(g, with_labels=True)
#plt.show(block=True)

session = tfs.Session()
output = session.run(z, {x: 1.0})
print(output)

print(z.input_nodes[0], z.input_nodes[1])
print(z.output)
print(z.consumers)
print(y.consumers[0])
print(x.consumers[0])
print(a.consumers[0])
print(a.consumers)
예제 #2
0
# Create variables
a = tfg.Variable(apple_price, name="a")
b = tfg.Variable(apple_num, name="b")

c = tfg.Variable(orange_price, name="c")
d = tfg.Variable(orange_num, name="d")

e = tfg.Variable(tax, name="e")

# Create Mul operation node
f = tfg.Mul(a, b, name="f")
g = tfg.Mul(c, d, name="g")

# Create Add operation node
h = tfg.Add(f, g, name="h")

# Create Mul operation node
i = tfg.Mul(h, e, name="i")

session = tfs.Session()
# forward
final_price = session.run(i, verbose=False)
print("final_price: {:f}".format(float(final_price)))

print()

#backward
d_in = 1
d_total_price, d_tax = i.backward(d_in)
print("d_total_price: {:f}".format(float(d_total_price)))
예제 #3
0
파일: tf_test.py 프로젝트: linklab/aiclass
g = tfg.Graph()  # 컴퓨테이션 그래프 클래스를 생성
#g.initialize() # 컴퓨테이션 그래프 클래스를 초기화
#"""
# Create variables
a = tfg.Variable(5.0, name="a")  #변수 클래스 a를 생성하고 초기화
b = tfg.Variable(-1.0, name="b")  #변수 클래스 b를 생성하고 초기화

# Create placeholder
x = tfg.Placeholder(name="x")  #플레이스홀더는 이후 입력할 값으로 현재는 값까지는 초기화하지 않음

# Create hidden node y
y = tfg.Mul(a, x, name="y")  #곱 연산 클래스를 생성

# Create output node z
z = tfg.Add(y, b, name="z")  #합 연산 클래스를 생성

#nx.draw_networkx(g, with_labels=True)
#plt.show(block=True)

# 수행~~~~~~~~~~~~~~~~~~~~~~
session = tfs.Session()
output = session.run(z, {x: 1.0})
print(output)
output = session.run(z, {x: 2.0})
print(output)
output = session.run(z, {x: 3.0})
print(output)
#"""
"""
# Create variables
예제 #4
0
 def __init__(self, weight_node, input_node, bias_node):
     # Create hidden node y
     y = tfg.Mul(weight_node, input_node)  #곱 연산 클래스를 생성
     # Create output node z
     z = tfg.Add(y, bias_node)  #합 연산 클래스를 생성
예제 #5
0
파일: layer.py 프로젝트: linklab/aiclass
 def __init__(self, weight_node, input_node, bias_node):
     y = tfg.Mul(weight_node, input_node)
     z = tfg.Add(y, bias_node)