Я пытаюсь разработать CNN с несколькими входами, следуя архитектуре, которую я прочитал на Сверточная нейронная сеть с несколькими входами для классификации цветов .
У меня есть CSV-файл, в котором хранится значение для каждого элемента данных, и для каждого элемента я сделал 4 снимка с разных сторон. Когда я запускаю следующий код, сеть печатается правильно, но кажется, что она никогда не работает, поскольку ничего не происходит, и использование графического процессора с помощью nvidia-smi ниже 5%.
kilograms_trees = tf.data.experimental.CsvDataset(
filenames='dataset/agrumeto.csv',
record_defaults=[tf.float32],
field_delim=",",
header=True)
kilo_train = kilograms_trees.take(35)
kilo_test = kilograms_trees.skip(35)
def create_conv_layer(input):
x = tf.keras.layers.Conv2D(32, (7, 7), activation='relu')(input)
x = tf.keras.layers.MaxPooling2D((2, 2), (2,2))(x)
x = tf.keras.Model(inputs=input, outputs=x)
return x
inputA = tf.keras.Input(shape=(size,size,3))
inputB = tf.keras.Input(shape=(size,size,3))
inputC = tf.keras.Input(shape=(size,size,3))
inputD = tf.keras.Input(shape=(size,size,3))
x = create_conv_layer(inputA)
y = create_conv_layer(inputB)
w = create_conv_layer(inputC)
z = create_conv_layer(inputD)
# combine the output of the two branches
combined = tf.keras.layers.concatenate([x.output, y.output, w.output, z.output])
layer_1 = tf.keras.layers.Conv2D(16, (3,3), activation="relu")(combined)
layer_1 = tf.keras.layers.MaxPooling2D((2, 2))(layer_1)
layer_2 = tf.keras.layers.Conv2D(16, (3,3), activation="relu")(layer_1)
layer_2 = tf.keras.layers.MaxPooling2D((2, 2), (2,2))(layer_2)
layer_3 = tf.keras.layers.Conv2D(32, (3,3), activation="relu")(layer_2)
layer_3 = tf.keras.layers.MaxPooling2D((2, 2), (2,2))(layer_3)
layer_4 = tf.keras.layers.Conv2D(32, (3,3), activation="relu")(layer_3)
layer_4 = tf.keras.layers.MaxPooling2D((2, 2), (2,2))(layer_4)
flatten = tf.keras.layers.Flatten()(layer_4)
hidden1 = tf.keras.layers.Dense(10, activation='relu')(flatten)
output = tf.keras.layers.Dense(1, activation='relu')(hidden1)
model = tf.keras.Model(inputs=[x.input, y.input, w.input, z.input], outputs=output)
print(model.summary())
model.compile(optimizer='adam',
loss="mean_absolute_percentage_error")
print("[INFO] training model...")
model.fit([trainA, trainB, trainC, trainD], kilo_train, epochs=5, batch_size=4)
test_loss, test_acc = model.evaluate([testA, testB, testC, testD], kilo_test)
print(test_acc)
Ниже приведен вывод nvidia-smi:
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.40.04 Driver Version: 418.40.04 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1050 On | 00000000:01:00.0 Off | N/A |
| N/A 54C P0 N/A / N/A | 3830MiB / 4042MiB | 8% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 909 C ...ycharmProjects/agrumeto/venv/bin/python 3159MiB |
| 0 1729 G /usr/lib/xorg/Xorg 27MiB |
| 0 1870 G /usr/bin/gnome-shell 69MiB |
| 0 6290 G /usr/lib/xorg/Xorg 273MiB |
| 0 6420 G /usr/bin/gnome-shell 127MiB |
| 0 6834 G ...quest-channel-token=6261236721362009153 85MiB |
| 0 8806 G ...pycharm-professional/132/jre64/bin/java 2MiB |
| 0 12830 G ...-token=60E939FEF0A8E3D5C46B3D6911048536 31MiB |
| 0 27478 G ...-token=ECA4D3D9ADD8448674D34492E89E40E3 51MiB |
+-----------------------------------------------------------------------------+
и это последние несколько строк консоли вывода:
conv2d_7 (Conv2D) (None, 14, 14, 32) 9248 max_pooling2d_6[0][0]
__________________________________________________________________________________________________
max_pooling2d_7 (MaxPooling2D) (None, 7, 7, 32) 0 conv2d_7[0][0]
__________________________________________________________________________________________________
flatten (Flatten) (None, 1568) 0 max_pooling2d_7[0][0]
__________________________________________________________________________________________________
dense (Dense) (None, 10) 15690 flatten[0][0]
__________________________________________________________________________________________________
dense_1 (Dense) (None, 1) 11 dense[0][0]
==================================================================================================
Total params: 69,301
Trainable params: 69,301
Non-trainable params: 0
__________________________________________________________________________________________________
None
[INFO] training model...