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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使張量流模型將列表作為輸入?

如何使張量流模型將列表作為輸入?

絕地無雙 2023-06-20 16:02:30
我是 tensorflow 的新手,我正在制作一個可以進行乘法運算的 AI,我需要制作它以便我的模型可以將列表作為輸入。這是我的代碼:import tensorflow as tfimport numpy as npimport matplotlib.pyplot as pltmultiplication_q = np.array([[10,10],[1,1],[2,2],[0,0],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[1,0],[11,10],[27,0],[30,2],[4,3],[17,22],[20,0],[8,13],[21,4],[19,24],[11,19],[8,2],[4,5],[11,11],[1,15],[2,12],[15,3],[18,0],[49,7],[5,7],[12,4]], dtype=object)multiplication_a = np.array([100,1,4,0,9,16,25,36,49,64,96,0,110,0,60,12,374,0,104,84,456,209,16,20,121,15,24,45,0,343,35,48], dtype=float)model = tf.keras.Sequential([  tf.keras.layers.Dense(units=4, input_shape=[1]),  tf.keras.layers.Dense(units=4),  tf.keras.layers.Dense(units=1)])model.compile(loss='mean_squared_error', optimizer=tf.keras.optimizers.Adam(0.1))history = model.fit(multiplication_q, multiplication_a, epochs=750, verbose=False)print(model.predict([4, 5]))這是錯誤消息:ValueError: in user code:    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:806 train_function  *        return step_function(self, iterator)    /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py:796 step_function  **        outputs = model.distribute_strategy.run(run_step, args=(data,))    /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:1211 run        return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)    /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2585 call_for_each_replica        return self._call_for_each_replica(fn, args, kwargs)    /usr/local/lib/python3.6/dist-packages/tensorflow/python/distribute/distribute_lib.py:2945 _call_for_each_replica        return fn(*args, **kwargs)
查看完整描述

2 回答

?
撒科打諢

TA貢獻1934條經(jīng)驗 獲得超2個贊

要解決您的問題,您應(yīng)該做三件事:

1- 將dtypefrom更改為這樣multiplication_qobjectint

multiplication_q = np.array([[10,10],[1,1],[2,2],[0,0],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[1,0],[11,10],[27,0],[30,2],[4,3],[17,22],[20,0],[8,13],[21,4],[19,24],[11,19],[8,2],[4,5],[11,11],[1,15],[2,12],[15,3],[18,0],[49,7],[5,7],[12,4]], dtype=int)

2- 在模型的第一個 Dense 層中使用input_shape=(2,)而不是input_shape=[1],如下所示:

model = tf.keras.Sequential([
  tf.keras.layers.Dense(units=4, input_shape=(2,)),
  tf.keras.layers.Dense(units=4),
  tf.keras.layers.Dense(units=1)
])

3- 對于預(yù)測函數(shù),你應(yīng)該傳遞一個listoflist而不是 a ,因為你用oflist進行了訓(xùn)練listlist

model.predict([[4, 5]])


查看完整回答
反對 回復(fù) 2023-06-20
?
慕的地8271018

TA貢獻1796條經(jīng)驗 獲得超4個贊

嘗試將第一個密集層中的輸入設(shè)置為,將輸入multiplication_q.shape形狀設(shè)置為132, 2


編輯:下面的代碼解決了您的問題,盡管您將不得不嘗試一些東西,因為它不是很準確。


import tensorflow as tf

import numpy as np

import matplotlib.pyplot as plt


multiplication_q = np.asarray([[10,10],[1,1],[2,2],[0,0],[3,3],[4,4],[5,5],[6,6],[7,7],[8,8],[9,9],[1,0],[11,10],[27,0],[30,2],[4,3],[17,22],[20,0],[8,13],[21,4],[19,24],[11,19],[8,2],[4,5],[11,11],[1,15],[2,12],[15,3],[18,0],[49,7],[5,7],[12,4]])

multiplication_a = np.asarray([100,1,4,0,9,16,25,36,49,64,96,0,110,0,60,12,374,0,104,84,456,209,16,20,121,15,24,45,0,343,35,48])



multiplication_q = multiplication_q/np.amax(multiplication_q)

multiplication_a = multiplication_a/np.amax(multiplication_a)



model = tf.keras.models.Sequential()

model.add(tf.keras.Input(shape=(2, )))

model.add(tf.keras.layers.Dense(32, activation='relu'))

model.add(tf.keras.layers.Dense(units=1))



model.compile(loss='mean_squared_error', optimizer=tf.keras.optimizers.Adam(0.1))


history = model.fit(multiplication_q, multiplication_a, epochs=750)


print(model.predict(np.asarray([[4, 5]])/np.amax(multiplication_q)*np.amax(multiplication_a)))



查看完整回答
反對 回復(fù) 2023-06-20
  • 2 回答
  • 0 關(guān)注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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