I have been trying to make my own generator that would handle an [image, float] value for the x (input), while the y is an int (linear output). My data is compiled into a .csv file. Can someone help me plug this data into a model.fit. I am not very confident in mixed data so there may be more than one problem.

I am currently using:

python 3.8\
tf-gpu 2.4.0rc1\
keras 2.4.3\
pandas 1.1.4

My code:

IMG_SIZE = 400
Version = 1
batch_size = 8

image_list = glob('F:/DATA/Vote/Images/**', recursive=True)
traindf = pd.read_csv('F:/DATA/Vote/Vote_Age.csv', index_col='ID')
del image_list[0] #First path did not lead to an image

def age_link(df, image_name):
    csv_row = df.loc[int(image_name), :]
    return csv_row[0]

def votes_link(df, image_name):
    csv_row = df.loc[int(image_name), :]
    return csv_row[1]

def generator(df, image_list, batch_size, IMG_SIZE):
    while True:
        for i in range(batch_size):
            image_path = image_list[i]
            image_name = os.path.basename(image_path).replace('.jpg', '')
            image = load_img(image_path, target_size=(IMG_SIZE, IMG_SIZE))
            image = np.array(image) / 255

            age = age_link(df, image_name)
            votes = votes_link(df, image_name)

            return np.asarray([image, age], dtype=object), votes

inputA = Input(shape=(IMG_SIZE, IMG_SIZE, 3))
inputB = Input(shape=(1,))

y = Conv2D(16, 3, activation = 'relu')(inputA)
y = Conv2D(16, 3, activation = 'relu')(y)
y = Conv2D(32, 3, activation = 'relu')(y)
y = Conv2D(32, 3, activation = 'relu')(y)
y = Flatten()(y)
y = Dense(4, activation="relu")(y)
y = Model(inputs=inputA, outputs=y)

x = Dense(8, activation="relu")(inputB)
x = Dense(4, activation="relu")(x)
x = Model(inputs=inputB, outputs=x)

combined = concatenate([x.output, y.output])

z = Dense(2, activation="relu")(combined)
z = Dense(1, activation="linear")(z)

model = Model(inputs=[inputA, inputB], outputs=z)
model.compile(loss="mean_absolute_percentage_error", optimizer='adam')

model.fit(generator(traindf, image_list, batch_size, IMG_SIZE),
    epochs=200, batch_size=8)

Output Error:

Traceback (most recent call last):
  File "f:\PYTHON\YiffMiner\TrainYIFF_Votes.py", line 91, in <module>
    model.fit(generator(traindf, image_list, batch_size, IMG_SIZE),
  File "C:\Users\Tristan\anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1050, in fit
    data_handler = data_adapter.DataHandler(
  File "C:\Users\Tristan\anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 1099, in __init__
    adapter_cls = select_data_adapter(x, y)
  File "C:\Users\Tristan\anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\engine\data_adapter.py", line 961, in select_data_adapter
    raise ValueError(
ValueError: Failed to find data adapter that can handle input: (<class 'tuple'> containing values of types {"<class 'numpy.float64'>", "<class 'numpy.ndarray'>"}), <class 'NoneType'>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.