Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



 1238

I need help with my code

by Tenngage - 28 February, 2022 - 10:13 PM
This post is by a banned member (Tenngage) - Unhide
Tenngage  
Registered
143
Posts
8
Threads
2 Years of service
#1
It's a modified version of the code: https://github.com/sparsh0427/Palm-Vein-Authentication
 
My version is: https://anonfiles.com/NdF3bcLcx1/Code_py
 
The dataset I'm using: https://drive.google.com/drive/folders/1...sp=sharing
 
 
The error I am getting
Code:
training model
Epoch 1/5
WARNING:tensorflow:Model was constructed with shape (None, 600, 600) for input KerasTensor(type_spec=TensorSpec(shape=(None, 600, 600), dtype=tf.float32, name='flatten_8_input'), name='flatten_8_input', description="created by layer 'flatten_8_input'"), but it was called on an input with incompatible shape (None, 600, 600, 3).
Traceback (most recent call last):

  File "C:\Users\pc\Desktop\Palm-Vein-Authentication-master\Code.py", line 38, in <module>
    model.fit(train_images, train_labels, epochs=5)

  File "C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None

  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\func_graph.py", line 1147, in autograph_handler
    raise e.ag_error_metadata.to_exception(e)

ValueError: in user code:

    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 1021, in train_function  *
        return step_function(self, iterator)
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 1010, in step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 1000, in run_step  **
        outputs = model.train_step(data)
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py", line 859, in train_step
        y_pred = self(x, training=True)
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
        raise e.with_traceback(filtered_tb) from None
    File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\input_spec.py", line 248, in assert_input_compatibility
        raise ValueError(

    ValueError: Exception encountered when calling layer "sequential_8" (type Sequential).
    
    Input 0 of layer "dense_16" is incompatible with the layer: expected axis -1 of input shape to have value 360000, but received input with shape (None, 1080000)
    
    Call arguments received:
      • inputs=tf.Tensor(shape=(None, 600, 600, 3), dtype=float32)
      • training=True
      • mask=None

 
 
Help please
 
My telegram: @Grim2018
 
My discord: Th3 Sk!ller#8492
This post is by a banned member (UberFuck) - Unhide
UberFuck  
Godlike
1.557
Posts
375
Threads
5 Years of service
#2
(28 February, 2022 - 10:13 PM)AmericanHistoryX Wrote: Show More

So, I didn't look into that much and don't have TensorFlow loaded on my system, but one thing stood out...
 
Code:
 
for i in range(1, num_right_train):
    pic = np.array(Image.open("C:/Users/pc/Desktop/train/right_thr/" + str(1) + ".jpg"))    # << shouldn't this be str(i)
    train_images = np.vstack((train_images, np.array([pic])))

for i in range(num_left_train):
    pic = np.array(Image.open("C:/Users/pc/Desktop/train/left_thr/" + str(1) + ".jpg"))     # << shouldn't this be str(i)
    train_images = np.vstack((train_images, np.array([pic])))

Basically it's repeatedly taking the same jpeg to stack on the numpy array.  Not sure if that was a typo that got put in there when you were going from Python 2 -> Python 3.
This post is by a banned member (Tenngage) - Unhide
Tenngage  
Registered
143
Posts
8
Threads
2 Years of service
#3
I use the latest version of python, how do I make the transition, if you could help, I would really appreciate it, I'm short handed
This post is by a banned member (UberFuck) - Unhide
UberFuck  
Godlike
1.557
Posts
375
Threads
5 Years of service
#4
This was bugging me so I went ahead and looked at the training images.  Try using this instead for the first part...
 
Code:
import cv2
import numpy as np
import os
import tensorflow as tf
from tensorflow import keras
from PIL import Image

# CODE_DIR = os.path.abspath(os.path.dirname(__file__))
# TRAIN_PATH = os.path.join(CODE_DIR, 'train')
TRAIN_PATH = 'C:/Users/pc/Desktop/train'

print ("training model")

classes = ["left", "right"]

num_right_train = 50
num_left_train = 50

pic = np.array(Image.open(os.path.join(TRAIN_PATH,'right_thr', '1.jpg')).convert('L'))
train_images = np.array([pic])
train_labels = np.array([1]*num_right_train + [0]*num_left_train)

for i in range(2, num_right_train + 1):
    pic = np.array(Image.open(os.path.join(TRAIN_PATH,'right_thr', f'{i}.jpg')).convert('L'))
    train_images = np.vstack((train_images, np.array([pic])))

for i in range(1, num_left_train + 1):
    pic = np.array(Image.open(os.path.join(TRAIN_PATH,'left_thr', f'{i}.jpg')).convert('L'))
    train_images = np.vstack((train_images, np.array([pic])))


So this...
Quote:WARNING:tensorflow:Model was constructed with shape (None, 600, 600) for input KerasTensor(type_spec=TensorSpec(shape=(None, 600, 600), dtype=tf.float32, name='flatten_8_input'), name='flatten_8_input', description="created by layer 'flatten_8_input'"), but it was called on an input with incompatible shape (None, 600, 600, 3)

...was bitching about the the numpy arrays being different shapes.  Basically the input images were RGB (even though they were black and white), which is why the array is 3 dimensional (600x600 for R channel, 600x600 for G channel, 600x600 for B channel).  Doing a convert('L') puts it in greyscale, which is two dimensional.

Also, since your images start with 1 and end with 50, the for loop ranges needed to be adjusted.
This post is by a banned member (Tenngage) - Unhide
Tenngage  
Registered
143
Posts
8
Threads
2 Years of service
#5
(This post was last modified: 01 March, 2022 - 04:30 AM by Tenngage. Edited 2 times in total.)
Ikr! I will replace the first part and get back for an update

Could it be the dataset causing this shit?

Problem solved, thank you so much foxegado  

[Image: 1.png]

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 3 Guest(s)