#๐ Tensorflow Question
28 messages ยท Page 1 of 1 (latest)
@thorn dew
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
try showing the code also (as text)
!code
import tensorflow as tf
import tensorflow_datasets as tfds
from tensorflow.keras.layers import Dense, Dropout, GlobalAveragePooling2D, Input, Lambda
# Load MNIST dataset without shuffling
mnist_dataset, mnist_info = tfds.load(name='mnist', with_info=True, as_supervised=True)
# Split dataset into training and testing sets
mnist_train, mnist_test = mnist_dataset['train'], mnist_dataset['test']
def preprocess_data(image, label):
image = tf.image.resize(image, [32, 32])
image = tf.image.grayscale_to_rgb(image)
image = tf.cast(image, tf.float32)
image /= 255.0
label = tf.one_hot(label, depth=10)
return image, label
# Preprocess training and testing data
mnist_train = mnist_train.map(preprocess_data)
mnist_test = mnist_test.map(preprocess_data)
# Define InceptionV3 base model
base_inception = tf.keras.applications.InceptionV3(include_top=False,
input_shape=(224, 224, 3))
# Define model architecture
input_layer = Input(shape=(32, 32, 3))
resizing_layer = Lambda(lambda image: tf.image.resize(image, (32, 32)))(input_layer)
inception_layers = base_inception(resizing_layer, training=False)
glob_pooling = GlobalAveragePooling2D()(inception_layers)
layer_i = Dense(500, activation='relu')(glob_pooling)
dropout_layer = Dropout(0.3)(layer_i)
output_layer = Dense(10, activation='softmax')(dropout_layer)
model = tf.keras.Model(inputs=input_layer, outputs=output_layer)
# Freeze the base network
base_inception.trainable = False
# Compile the model
optimizer = tf.keras.optimizers.Adam()
model.compile(optimizer=optimizer,
loss='categorical_crossentropy',
metrics=['accuracy'])
# Train the model
history = model.fit(
mnist_train,
validation_data=mnist_test,
batch_size=64,
epochs=2,
verbose=2
)
# Evaluate the model
results = model.evaluate(mnist_test)
print("Test Loss:", results[0])
print("Test Accuracy:", results[1])
u mean the progress bar
yeah, sorry, the progress bar, never had "unknown" appear tho
It gave an error when I switched it to 1.....
I'll just try to look over my code some more, I don't think changing the verbose should give me an error
yeah, been struggling with it for a bit. It's probably something else
if im not wrong the mnist dataset is greyscale so the input shape in ur input layer should be 32,32,1
that might be the issue
well, the InceptionV3 takes rgb, not greyscale, so I had to change it to rgb
at least I think. I just used VGG16 and also had issues with rgb/greyscale
and it had to take rgb
ah i see
yeah, its been a pain
is this for an assignment or something
i mean u could just use a lenet5 for the mnist dataset and you would still get a high accuracy
Well, it's for an image classification project. I'll have to eventually run my own dataset through, but my prof suggested practicing with mnist
but I have to use InceptionV3 and VGG16 for the project
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.