I was trying to use the Keras ResNet 50 application model on my problem with this code:
#Tensorflow and tf.keras
import tensorflow as tf
from tensorflow import keras
#tf.enable_eager_execution()
#Helper libraries
import numpy as np
import matplotlib.pyplot as plt
import Muenzbetragserkennung_input_ResNet
#print(tf.__version__)
#Dataset
#Training and test data
(train_images, train_labels), (test_images, test_labels) =
Muenzbetragserkennung_input_ResNet.read_input_shuffle()
batch_size, height, width, channels = train_images.shape
train_images = train_images / 255.0
test_images = test_images / 255.0
print(train_images.shape)
#Build the model
model = tf.keras.applications.resnet50.ResNet50(include_top=False,
weights=None, input_tensor=None, input_shape=(height, width, channels),
pooling='max')
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='mean_squared_error',
metrics=['accuracy'])
#model.summary()
#Train
model.fit(train_images, train_labels, epochs=10)
#model.save_weights('models/muenzen.h5')
#Evaluate
loss, accuracy = model.evaluate(test_images, test_labels)
print('Accuracy', accuracy)
#Prediction
prediction = model.predict(test_images[0:1])
print(prediction)
But got the following Ouput/Error:
Shape train images: (3865, 240, 320, 3)
Shape train labels: (3865,)
Shape test images: (967, 240, 320, 3)
Shape test labels: (967,)
(3865, 240, 320, 3)
Traceback (most recent call last):
File"C:/Users/Christian/PycharmProjects/MuenzbetragserkennungResNet/Muenzbetragserkennung_ResNet.py", line 34, in model.fit(train_images, train_labels, epochs=10)File "C:\Users\Christian\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\training.py", line 1278, in fit validation_split=validation_split)
File "C:\Users\Christian\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\training.py", line 917, in _standardize_user_data exception_prefix='target')
File "C:\Users\Christian\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\training_utils.py", line 191, in standardize_input_data ' but got array with shape ' + str(data_shape))
ValueError: Error when checking target: expected global_max_pooling2d to have shape (2048,) but got array with shape (1,)
Process finished with exit code 1
I already tried different pooling versions, but only got other ValueErrors. The model should output one value (worth of coins in the image).
Thank you in advance for your help.