当我尝试在我的 Jupyter-notebook 模型中使用这个测试和有效生成器时。
我通过以下代码执行它:
IMAGE_DIR = "/Users/awabe/Desktop/Project/PapilaDB/FundusImages test"
valid_generator, test_generator= get_test_and_valid_generator(valid_df, test_df, train_df, IMAGE_DIR, "Image", labels)
然后它给了我错误:
获得火车和有效的发电机...... 找到 0 个经过验证的图像文件名。
/opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/keras/preprocessing/image.py:1139: UserWarning: Found 488 invalid image filename(s) in x_col="Image". These filename(s) will be ignored.
warnings.warn(
/opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/numpy/core/fromnumeric.py:3432: RuntimeWarning: Mean of empty slice.
return _methods._mean(a, axis=axis, dtype=dtype,
/opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/numpy/core/_methods.py:182: RuntimeWarning: invalid value encountered in divide
ret = um.true_divide(
/opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/numpy/core/_methods.py:265: RuntimeWarning: Degrees of freedom <= 0 for slice
ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
/opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/numpy/core/_methods.py:223: RuntimeWarning: invalid value encountered in divide
arrmean = um.true_divide(arrmean, div, out=arrmean, casting='unsafe',
/opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/numpy/core/_methods.py:254: RuntimeWarning: invalid value encountered in divide
ret = um.true_divide(
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[73], line 2
1 IMAGE_DIR = "/Users/awabe/Desktop/Project/PapilaDB/FundusImages test"
----> 2 valid_generator, test_generator= get_test_and_valid_generator(valid_df, test_df, train_df, IMAGE_DIR, "Image", labels)
Cell In[57], line 50, in get_test_and_valid_generator(valid_df, test_df, train_df, image_dir, x_col, y_cols, sample_size, batch_size, seed, target_w, target_h)
47 image_generator.fit(data_sample)
49 # get test generator
---> 50 valid_generator = image_generator.flow_from_dataframe(
51 dataframe=valid_df,
52 directory=image_dir,
53 x_col=x_col,
54 y_col=y_cols,
55 class_mode="raw",
56 batch_size=batch_size,
57 shuffle=False,
58 seed=seed,
59 target_size=(target_w,target_h))
63 test_generator = image_generator.flow_from_dataframe(
64 dataframe=test_df,
65 directory=image_dir,
(...)
71 seed=seed,
72 target_size=(target_w,target_h))
75 return valid_generator, test_generator
File /opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/keras/preprocessing/image.py:1808, in ImageDataGenerator.flow_from_dataframe(self, dataframe, directory, x_col, y_col, weight_col, target_size, color_mode, classes, class_mode, batch_size, shuffle, seed, save_to_dir, save_prefix, save_format, subset, interpolation, validate_filenames, **kwargs)
1801 if "drop_duplicates" in kwargs:
1802 warnings.warn(
1803 "drop_duplicates is deprecated, you can drop duplicates "
1804 "by using the pandas.DataFrame.drop_duplicates method.",
1805 DeprecationWarning,
1806 )
-> 1808 return DataFrameIterator(
1809 dataframe,
1810 directory,
1811 self,
1812 x_col=x_col,
1813 y_col=y_col,
1814 weight_col=weight_col,
1815 target_size=target_size,
1816 color_mode=color_mode,
1817 classes=classes,
1818 class_mode=class_mode,
1819 data_format=self.data_format,
1820 batch_size=batch_size,
1821 shuffle=shuffle,
1822 seed=seed,
1823 save_to_dir=save_to_dir,
1824 save_prefix=save_prefix,
1825 save_format=save_format,
1826 subset=subset,
1827 interpolation=interpolation,
1828 validate_filenames=validate_filenames,
1829 dtype=self.dtype,
1830 )
File /opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/keras/preprocessing/image.py:968, in DataFrameIterator.__init__(self, dataframe, directory, image_data_generator, x_col, y_col, weight_col, target_size, color_mode, classes, class_mode, batch_size, shuffle, seed, data_format, save_to_dir, save_prefix, save_format, subset, interpolation, keep_aspect_ratio, dtype, validate_filenames)
966 self.dtype = dtype
967 # check that inputs match the required class_mode
--> 968 self._check_params(df, x_col, y_col, weight_col, classes)
969 if (
970 validate_filenames
971 ): # check which image files are valid and keep them
972 df = self._filter_valid_filepaths(df, x_col)
File /opt/anaconda3/envs/tensorflow/lib/python3.10/site-packages/keras/preprocessing/image.py:1030, in DataFrameIterator._check_params(self, df, x_col, y_col, weight_col, classes)
1028 # check that filenames/filepaths column values are all strings
1029 if not all(df[x_col].apply(lambda x: isinstance(x, str))):
-> 1030 raise TypeError(
1031 "All values in column x_col={} must be strings.".format(x_col)
1032 )
1033 # check labels are string if class_mode is binary or sparse
1034 if self.class_mode in {"binary", "sparse"}:
TypeError: All values in column x_col=Image must be strings.
我该怎么办?我尝试了很多解决方案来改变类型
我也在寻找这个生成器“表单”的任何参考,但我没有找到它。
如果您有标准表格的链接,请附上!>