Tensofflow model returns random predictions

I am new to ML and tensorflow

I have a python script to load and train my model, which trains very fast, but being a newbie, I don’t really know what it should do.

The source images are vertically oriented pennies (lincoln’s head is upright) @ 400x400x3

my image dataset is built using only 10 master images that I augment manually to get rotated and shifted images in the dataset
10 images x 90 rotations == 900 images non-shifted
or
10 images x 90 rotations x 17 shifts == 15300 images shifted

I have not been able to find an example of building a custom image dataset like this. all of the examples seem to focus on using a pre-existing mnist dataset, or using image_dataset_from_directory, which expects all of the files to exist.

Because I an unsure if the problem is image related, I am only using the non-shifted images for testing.

The test images are what the training images were created from, before they were rotated to the correct orientation, so in my deductive reasoning, I should have a high probability of matching on something….

When I run predictions from test images, the results seem random.

I have tried various layers, image resolutions, all with similar results.

while training the accuracy seems very low to me.

again, I am new to ML and tensorflow, so I don’t know what “normal” is…

Because the issue (or issues) can be in so many places, I don’t really know where to start.

images:

def LoadImage(path):
    # load and normalize an image
    #print('loading image '+path)
    img = cv2.imread(path)
    img = cv2.resize(img, (IMAGE_SIZE, IMAGE_SIZE))
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img = img.astype(float) / 255.0
    return img

baseimg = LoadImage(TrainingImagesDir+f)
for angle in range(0,360,4):
    rotated = RotateImage(baseimg, angle)
    label = 0 + int(angle/4)
    train_images.append(rotated)
    train_labels.append(label)

dataset:

train_images_tensor = tf.convert_to_tensor(train_images, name='train images')
train_labels_tensor = tf.convert_to_tensor(train_labels, name='train labels')

train_ds = tf.data.Dataset.from_tensors((train_images_tensor, train_labels_tensor))

model:

    model = tf.keras.models.Sequential([
        tf.keras.layers.Flatten(input_shape=(IMAGE_SIZE,IMAGE_SIZE)),
        tf.keras.layers.Dense(128, activation='relu'),
        tf.keras.layers.Dropout(0.2),
        tf.keras.layers.Dense(len(arrClasses))
    ])
    loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)

    opt = tf.keras.optimizers.Adam(learning_rate=1e-5)

    model.compile(
        optimizer=opt,
        loss=loss_fn,
        metrics=['accuracy']
    )

training:

tensorboard_callback = keras.callbacks.TensorBoard(log_dir=LogDir)

model.fit(
    train_ds,
    validation_data=valid_ds,
    verbose=1,
    epochs=EPOCHS,
    callbacks=[tensorboard_callback]
)

I have tried to change the layers by referencing different sample code online, but I do not understand how to pick the different layers to identify “features”. I haven’t found a good resource to guide me.
Before I go down the rabbit hole of fixing the model definition, I would like to confirm that is the issue.

Epoch 1/10 1/1 [==============================] - 1s 938ms/step - loss: 4.7652 - accuracy: 0.0116 - val_loss: 4.6423 - val_accuracy: 0.0000e+00 Epoch 2/10 1/1 [==============================] - 0s 313ms/step - loss: 4.7536 - accuracy: 0.0112 - val_loss: 4.6310 - val_accuracy: 0.0000e+00 Epoch 3/10 1/1 [==============================] - 0s 266ms/step - loss: 4.7422 - accuracy: 0.0109 - val_loss: 4.6199 - val_accuracy: 0.0000e+00 Epoch 4/10 1/1 [==============================] - 0s 266ms/step - loss: 4.7329 - accuracy: 0.0119 - val_loss: 4.6088 - val_accuracy: 0.0000e+00 Epoch 5/10 1/1 [==============================] - 0s 328ms/step - loss: 4.7249 - accuracy: 0.0125 - val_loss: 4.5982 - val_accuracy: 0.0000e+00 Epoch 6/10 1/1 [==============================] - 0s 423ms/step - loss: 4.7147 - accuracy: 0.0128 - val_loss: 4.5878 - val_accuracy: 0.0000e+00 Epoch 7/10 1/1 [==============================] - 0s 312ms/step - loss: 4.7023 - accuracy: 0.0122 - val_loss: 4.5784 - val_accuracy: 0.0000e+00 Epoch 8/10 1/1 [==============================] - 0s 312ms/step - loss: 4.6969 - accuracy: 0.0112 - val_loss: 4.5697 - val_accuracy: 0.0000e+00 Epoch 9/10 1/1 [==============================] - 0s 360ms/step - loss: 4.6897 - accuracy: 0.0121 - val_loss: 4.5618 - val_accuracy: 0.0000e+00 Epoch 10/10 1/1 [==============================] - 0s 390ms/step - loss: 4.6806 - accuracy: 0.0120 - val_loss: 4.5546 - val_accuracy: 0.0000e+00

New contributor

skeeter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật