-
大小: 3.24KB文件類型: .py金幣: 1下載: 0 次發布日期: 2021-03-03
- 語言: Python
- 標簽: tensorflow??and??xor??
資源簡介
在tensorflow中實現的and和xor函數的例子
代碼片段和文件信息
#!/usr/bin/env?python
import?tensorflow?as?tf
import?math
import?numpy?as?np
INPUT_COUNT?=?2
OUTPUT_COUNT?=?2
HIDDEN_COUNT?=?2
LEARNING_RATE?=?0.1
MAX_STEPS?=?5000
#?For?every?training?loop?we?are?going?to?provide?the?same?input?and?expected?output?data
INPUT_TRAIN?=?np.array([[0?0]?[0?1]?[1?0]?[1?1]])
OUTPUT_TRAIN?=?np.array([[1?0]?[0?1]?[0?1]?[1?0]])
#?Nodes?are?created?in?Tensorflow?using?placeholders.?Placeholders?are?values?that?we?will?input?when?we?ask?Tensorflow?to?run?a?computation.
#?Create?inputs?x?consisting?of?a?2d?tensor?of?floating?point?numbers
inputs_placeholder?=?tf.placeholder(“float“
shape=[None?INPUT_COUNT])
labels_placeholder?=?tf.placeholder(“float“
shape=[None?OUTPUT_COUNT])
#?We?need?to?create?a?python?dictionary?object?with?placeholders?as?keys?and?feed?tensors?as?values
feed_dict?=?{
inputs_placeholder:?INPUT_TRAIN
labels_placeholder:?OUTPUT_TRAIN
}
#?Define?weights?and?biases?from?input?layer?to?hidden?l
評論
共有 條評論