File “C:\Users\User.conda\envs\Sum\lib\site-packages\numpy\lib\npyio.py”, line 1382, in savetxt
raise ValueError(
ValueError: Expected 1D or 2D array, got 4D array instead
This kind of error i am getting…please give me solution.code has been attached below
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D
inputs_2 = keras.Input(shape=(224, 224, 3), name=“img”)
vgg = VGG16(input_tensor=inputs_2, weights=‘imagenet’, include_top=False)
for layer in vgg.layers:
layer.trainable = False
resnet = ResNet50(input_tensor=inputs_2, weights=‘imagenet’, include_top=False)
for layer in resnet.layers:
layer.trainable = False
mergedOutput = tf.keras.layers.concatenate([vgg.output, resnet.output])
#merged = keras.layers.GlobalAveragePooling2D()(mergedOutput) # This line
#x = keras.layers.Dense(256, activation=“relu”)(merged)
#prediction = Dense(3, activation=‘softmax’)(x)
model = Model(inputs=inputs_2, outputs=mergedOutput)
print(model.summary())
img_path = ‘img-1.png’
img = image.load_img(img_path, target_size=(224, 224))
x2 = image.img_to_array(img)
x2 = np.expand_dims(x2, axis=0)
x2 = preprocess_input(x2)
features = model.predict(x2)
np.savetxt(“feat-c.csv”,features,delimiter=“,”)