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

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

我收到此錯誤“模塊“tensorflow._api.v1.keras.layers”

我收到此錯誤“模塊“tensorflow._api.v1.keras.layers”

溫溫醬 2021-12-09 10:55:21
執(zhí)行以下代碼時出現(xiàn)上述錯誤。我正在嘗試在下面的 tensorflow 神經(jīng)網(wǎng)絡(luò)實現(xiàn)教程中解決這個問題。 https://www.datacamp.com/community/tutorials/tensorflow-tutorialdef load_data(data_directory):directories = [d for d in os.listdir(data_directory)                if os.path.isdir(os.path.join(data_directory, d))]labels = []images = []for d in directories:    label_directory = os.path.join(data_directory, d)    file_names = [os.path.join(label_directory, f)                   for f in os.listdir(label_directory)                   if f.endswith(".ppm")]    for f in file_names:        images.append(skimage.data.imread(f))        labels.append(int(d))return images, labelsimport osimport skimagefrom skimage import transformfrom skimage.color import rgb2grayimport numpy as npimport kerasfrom keras import layersfrom keras.layers import DenseROOT_PATH = "C://Users//Jay//AppData//Local//Programs//Python//Python37//Scriptcodes//BelgianSignals"train_data_directory = os.path.join(ROOT_PATH, "Training")test_data_directory = os.path.join(ROOT_PATH, "Testing")images, labels = load_data(train_data_directory)# Print the `labels` dimensionsprint(np.array(labels))# Print the number of `labels`'s elementsprint(np.array(labels).size)# Count the number of labelsprint(len(set(np.array(labels))))# Print the `images` dimensionsprint(np.array(images))# Print the number of `images`'s elementsprint(np.array(images).size)# Print the first instance of `images`np.array(images)[0]images28 = [transform.resize(image, (28, 28)) for image in images]images28 = np.array(images28)images28 = rgb2gray(images28)# Import `tensorflow` import tensorflow as tf # Initialize placeholders x = tf.placeholder(dtype = tf.float32, shape = [None, 28, 28])y = tf.placeholder(dtype = tf.int32, shape = [None])# Flatten the input dataimages_flat = tf.keras.layers.flatten(x)# Fully connected layer logits = tf.contrib.layers.dense(images_flat, 62, tf.nn.relu)
查看完整描述

2 回答

?
吃雞游戲

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

任何一個

from keras.layers import Flatten

并使用

Flatten()(input)

或者

簡單地使用

tf.keras.layers.Flatten()(input)


查看完整回答
反對 回復 2021-12-09
?
躍然一笑

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

新的(“keras 作為默認 API”)方法會讓你使用 keras 層,tf.keras.layers.Flatten但你似乎錯過了一些細微差別(評論中沒有提到)。


tf.keras.layers.Flatten() 實際上返回一個 keras 層(可調(diào)用)對象,該對象又需要與您的前一層一起調(diào)用。


所以更像是這樣的:


# Flatten the input data

flatten_layer = tf.keras.layers.Flatten()

images_flat = flatten_layer(x)

或者,為簡潔起見,只是:


# Flatten the input data

images_flat = tf.keras.layers.Flatten()(x)


查看完整回答
反對 回復 2021-12-09
  • 2 回答
  • 0 關(guān)注
  • 362 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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