#๐Ÿ”’ Tensorflow Question

28 messages ยท Page 1 of 1 (latest)

thorn dew
#

Has anyone seen this before in the command line? Usually mine displays an arrow, not sure if this means something went wrong?

hallow sailBOT
#

@thorn dew

Python help channel opened

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.

shadow pivot
#

!code

hallow sailBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

thorn dew
#
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])
thorn dew
#

yeah, sorry, the progress bar, never had "unknown" appear tho

haughty gate
#

set verbose=1 in the model.fit

#

it doesnt really affect anything tho

thorn dew
#

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

haughty gate
#

yea

#

verbose is just for logging so thats abit odd

thorn dew
#

yeah, been struggling with it for a bit. It's probably something else

haughty gate
#

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

thorn dew
#

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

haughty gate
#

ah i see

thorn dew
#

yeah, its been a pain

haughty gate
#

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

thorn dew
#

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

hallow sailBOT
#
Python help channel closed

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.