Using Keras ImageDataGenerator in a regression model

后端 未结 4 1564
别跟我提以往
别跟我提以往 2020-12-30 02:29

I want to use the

flow_from_directory

method of the

ImageDataGenerator

to generate training data for a

4条回答
  •  清酒与你
    2020-12-30 03:08

    There's just one glitch in the accepted answer that I would like to point out. The above code fails with an error message like:

    TypeError: only integer scalar arrays can be converted to a scalar index
    

    This is because y is an array. The fix is simple:

    def regression_flow_from_directory(flow_from_directory_gen,
                list_of_values):
        for x, y in flow_from_directory_gen:
            values = [list_of_values[y[i]] for i in range(len(y))]
            yield x, values
    

    The method to generate the list_of_values can be found in https://stackoverflow.com/a/47944082/4082092

提交回复
热议问题