第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

您必須為占位符張量“Placeholder”提供一個(gè)值,其數(shù)據(jù)類型為浮點(diǎn)型和形狀

您必須為占位符張量“Placeholder”提供一個(gè)值,其數(shù)據(jù)類型為浮點(diǎn)型和形狀

江戶川亂折騰 2022-01-05 19:24:22
我在我的 Pycharm 中編寫(xiě)了以下代碼,它在 Tensorflow 中執(zhí)行完全連接層 (FCL)。占位符發(fā)生無(wú)效參數(shù)錯(cuò)誤。所以我在占位符中輸入了所有dtype, shape, 和name,但我仍然收到無(wú)效參數(shù)錯(cuò)誤。我想通過(guò) FCL 模型制作新的 Signal(1, 222)。輸入信號(hào)(1, 222) => 輸出信號(hào)(1, 222)maxPredict: 找出輸出信號(hào)中具有最高值的索引。calculate Y: 獲取maxPredict對(duì)應(yīng)的頻率數(shù)組值。loss:使用真實(shí) Y 之間的差異并將 Y 計(jì)算為損失。loss = tf.abs(trueY - calculateY)`代碼(發(fā)生錯(cuò)誤)x = tf.placeholder(dtype=tf.float32, shape=[1, 222], name='inputX')錯(cuò)誤InvalidArgumentError(回溯見(jiàn)上文):您必須使用 dtype float 和 shape [1,222] tensorflow.python.framework.errors_impl.InvalidArgumentError 為占位符張量“inputX”提供一個(gè)值:您必須為占位符張量“inputX”提供一個(gè)值與 dtype float 和 shape [1,222] [[{{node inputX}} = Placeholderdtype=DT_FLOAT, shape=[1,222], _device="/job:localhost/replica:0/task:0/device:CPU:0"]] 在處理上述異常,又發(fā)生了一個(gè)異常:新的錯(cuò)誤案例我改變了我的代碼。x = tf.placeholder(tf.float32, [None, 222], name='inputX')錯(cuò)誤案例 1tensorFreq = tf.convert_to_tensor(basicFreq, tf.float32)newY = tf.gather(tensorFreq, maxPredict) * 60loss = tf.abs(y - tf.Variable(newY))ValueError:initial_value 必須指定一個(gè)形狀:Tensor("mul:0", shape=(?,), dtype=float32)錯(cuò)誤案例 2tensorFreq = tf.convert_to_tensor(basicFreq, tf.float32)newY = tf.gather(tensorFreq, maxPredict) * 60loss = tf.abs(y - newY)回溯(最近一次調(diào)用):文件“D:/PycharmProject/DetectionSignal/TEST_FCL_StackOverflow.py”,第 127 行,trainStep = opt.minimize(loss) 文件“C:\Users\Heewony\Anaconda3\envs\TSFW_pycharm\lib \site-packages\tensorflow\python\training\optimizer.py”,第 407 行,最小化([str(v) for _,v in grads_and_vars],loss))ValueError:沒(méi)有為任何變量提供梯度,檢查你的圖表對(duì)于不支持梯度的操作,變量之間 [tf.Variable 'Variable:0' shape=(222, 1024) dtype=float32_ref, tf.Variable 'Variable_1:0' shape=(1024,) dtype=float32_re, .. ....... tf.Variable 'Variable_5:0' shape=(222,) dtype=float32_ref] 和損失 Tensor("Abs:0", dtype=float32)。開(kāi)發(fā)環(huán)境操作系統(tǒng)平臺(tái)和發(fā)行版:Windows 10 x64TensorFlow 安裝自:AnacondaTensorflow 1.12.0 版:蟒蛇 3.6.7:移動(dòng)設(shè)備:不適用重現(xiàn)的確切命令:N/AGPU 型號(hào)和內(nèi)存:NVIDIA GeForce CTX 1080 TiCUDA/cuDNN:9.0/7.4
查看完整描述

2 回答

?
森林海

TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊

應(yīng)該有兩件事要改變。


錯(cuò)誤案例 0。您不需要重塑層之間的流程。您可以None在第一個(gè)維度上使用來(lái)傳遞動(dòng)態(tài)批量大小。


錯(cuò)誤案例 1.您可以直接使用 newY 作為 NN 的輸出。您只使用 tf.Variable 來(lái)定義權(quán)重或偏差。


錯(cuò)誤案例 2.似乎 tensorflow 沒(méi)有梯度下降實(shí)現(xiàn),也tf.abs()沒(méi)有tf.gather()。對(duì)于回歸問(wèn)題,均方誤差通常就足夠了。


在這里,我如何重寫(xiě)您的代碼。我沒(méi)有你的 matlab 部分,所以我無(wú)法調(diào)試你的 python/matlab 接口:


模型:


def Model_FCL(inputX):

    # Fully Connected Layer 1

    fcW1 = tf.get_variable('w1', shape=[222, 1024], initializer=tf.initializer.truncated_normal())

    fcb1 = tf.get_variable('b1', shape=[222], initializer=tf.initializer.truncated_normal())

    # fcb1 = tf.get_variable('b1', shape=[None, 222], trainable=False, initializer=tf.constant_initializer(valueThatYouWant)) # if you want to fix your bias constant

    fch1 = tf.nn.relu(tf.matmul(inputX, fcW1) + fcb1, name='relu1')


    # Fully Connected Layer 2

    fcW2 = tf.get_variable('w2', shape=[1024, 1024], initializer=tf.initializer.truncated_normal())

    fcb2 = tf.get_variable('b2', shape=[222], initializer=tf.initializer.truncated_normal())

    # fcb2 = tf.get_variable('b2', shape=[None, 222], trainable=False, initializer=tf.constant_initializer(valueThatYouWant)) # if you want to fix your bias constant

    fch2 = tf.nn.relu(tf.matmul(fch1, fcW2) + fcb2, name='relu2')


    # Output Layer

    fcW3 = tf.get_variable('w3', shape=[1024, 222], initializer=tf.initializer.truncated_normal())

    fcb3 = tf.get_variable('b3', shape=[222], initializer=tf.initializer.truncated_normal())

    # fcb2 = tf.get_variable('b2', shape=[None, 222], trainable=False, initializer=tf.constant_initializer(valueThatYouWant)) # if you want to fix your bias constant

    logits = tf.add(tf.matmul(fch2, fcW3), fcb3)


    predictY = tf.nn.softmax(logits)  #I'm not sure that it will learn if you do softmax then abs/MSE

    return predictY, logits

圖形:


with myGraph.as_default():

    # define input data & output data ???? ?? placeholder

    # put None(dynamic batch size) not -1 at the first dimension so that you can change your batch size

    x = tf.placeholder(tf.float32, shape=[None, 222], name='inputX')  # Signal size = [1, 222]

    y = tf.placeholder(tf.float32, shape=[None], name='trueY')  # Float value size = [1]


    ...


    predictY, logits = Model_FCL(x)  # Predict Signal, size = [1, 222]

    maxPredict = tf.argmax(predictY, 1, name='maxPredict')  # Find max index of Predict Signal


    tensorFreq = tf.convert_to_tensor(basicFreq, tf.float32)

    newY = tf.gather(tensorFreq, maxPredict) * 60   # Find the value that corresponds to the Freq array index


    loss = tf.losses.mean_squared_error(labels=y, predictions=newY)  # maybe use MSE for regression problem

    # loss = tf.abs(y - newY)  # Calculate absolute (true Y - predict Y) #tensorflow doesn't have gradient descent implementation for tf.abs

    opt = tf.train.AdamOptimizer(learning_rate=0.0001)

    trainStep = opt.minimize(loss)


查看完整回答
反對(duì) 回復(fù) 2022-01-05
?
小怪獸愛(ài)吃肉

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超1個(gè)贊

變量batchSignal的類型或形狀似乎錯(cuò)誤。它必須是一個(gè) numpy 形狀的數(shù)組[1, 222]。如果要使用一批大小為n × 222的示例,占位符x的形狀應(yīng)為[None, 222]和占位符y形狀 [None]。

順便說(shuō)一下,考慮使用tf.layers.dense而不是顯式初始化變量并自己實(shí)現(xiàn)層。


查看完整回答
反對(duì) 回復(fù) 2022-01-05
  • 2 回答
  • 0 關(guān)注
  • 254 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)