topic description
error setting an array element with a sequence.
sources of topics and their own ideas
error setting an array element with a sequence.
related codes
from keras.preprocessing.image import ImageDataGenerator
from keras.applications.imagenet_utils import preprocess_input
from PIL import Image
ppi = lambda x: Image.fromarray(preprocess_input(np.array(x).astype(np.float32)))
IMG_SIZE = (224, 224) -sharp slightly smaller than vgg16 normally expects
core_idg = ImageDataGenerator(samplewise_center=False,
samplewise_std_normalization=False,
horizontal_flip = True,
vertical_flip = False,
height_shift_range = 0.15,
width_shift_range = 0.15,
rotation_range = 5,
shear_range = 0.01,
fill_mode = "nearest",
zoom_range=0.2)
def flow_from_dataframe(img_data_gen, in_df, path_col, y_col, **dflow_args):
base_dir = os.path.dirname(in_df[path_col].values[0])
print("-sharp-sharp Ignore next message from keras, values are replaced anyways")
df_gen = img_data_gen.flow_from_directory(base_dir,
class_mode = "sparse",
**dflow_args)
df_gen.filenames = in_df[path_col].values
df_gen.classes = np.stack(in_df[y_col].values)
df_gen.samples = in_df.shape[0]
df_gen.n = in_df.shape[0]
df_gen._set_index_array()
df_gen.directory = "" -sharp since we have the full path
print("Reinserting dataframe: {} images".format(in_df.shape[0]))
return df_gen
train_gen = flow_from_dataframe(core_idg, train_df,
path_col = "path",
y_col = "cat_vec",
target_size = IMG_SIZE,
color_mode = "rgb",
batch_size = 32)
valid_gen = flow_from_dataframe(core_idg, valid_df,
path_col = "path",
y_col = "cat_vec",
target_size = IMG_SIZE,
color_mode = "rgb",
batch_size = 256) -sharp we can use much larger batches for evaluation
test_X, test_Y = next(flow_from_dataframe(core_idg, valid_df,
path_col = "path",
y_col = "cat_vec",
target_size = IMG_SIZE,
color_mode = "rgb",
batch_size = 256)) -sharp we can use much larger batches for evaluation