English 中文(简体)
Problem in fine tuning when I use "flow_from_dataframe"
原标题:

I use a CNN for classification using the following code (Summarized!) without problem.

cnn_input = Input((128, 32,3))
cnn_output = Conv2D(32, (3, 3), padding= same , activation=LeakyReLU(alpha=0.01)) (cnn_input)
fc_input = Flatten() (cnn_output)
fc_input = Dense(128, activation=LeakyReLU(alpha=0.01)) (fc_input)
full_output = Dense(8, activation="softmax") (fc_input)
model = models.Model(inputs=cnn_input, outputs=full_output)

But when I use a pretrained network (e.g., ResNet50 or VGG16) instead of the utilized CNN, I get the following error.

from tensorflow.keras.applications import ResNet50
feature_extractor = ResNet50(weights= imagenet , 
                         input_shape=(128, 32, 3),
                         include_top=False)
feature_extractor.trainable = False
input_ = tf.keras.Input(shape=(128, 32, 3))
x = feature_extractor(input_, training=False)
x = tf.keras.layers.Dense(128, activation= relu )(x)
output_ = tf.keras.layers.Dense(8, activation="softmax")(x)
model = tf.keras.Model(input_, output_)

Error:

categorical_crossentropy
        target.shape.assert_is_compatible_with(output.shape)

    ValueError: Shapes (None, None) and (None, None, None, 8) are incompatible

How to resolve this?

I tried to use a pretrained CNN using flow_from_dataframe, but I got an unexpected error that was not occurring in the case of utilizing a new CNN, while all conditions and code were the same!

问题回答

暂无回答




相关问题
Minimal diffusion model (DDIM) for MNIST

For the purpose of learning I created a minimal DDIM for the MNIST dataset. Everything besides the math of diffusions I consider "extras." Here is my list: U-Net (removed - replaced with ...

Pulling data from Object detection script

I am working on an AI project for school. Is it possible to pull data from a TF Object detection algorithm and then go do a google search/reverse image search whatever it is detecting then display ...

Tensorflow cannot detect CUDA enabled device

I have an RTX 4070 on my Dell XPS laptop that also comes with an Intel IRIS Xe Graphics card. I am using Windows 11. I have NVIDIA Graphics Driver Version 535.98 installed on my system and has support ...

Compiler error while compiling tensorflow_io in curve25519.c

I am trying to compile tensorflow_io onto my Ubuntu 22.04.2 target machine that does not offer GPU nor AVX instruction. I am finding that the compile errors out on curve25519.c. Is there a dependency ...

热门标签