这是我第一次尝试使用CNN做某事,因此我可能做的很愚蠢-但无法弄清楚我错了...
该模型似乎学习得很好,但是验证准确性并没有提高(甚至-在第一个时期之后),并且验证损失实际上随着时间而增加。看起来我不太适合(1个时期后?)-我们必须以其他方式关闭。
我正在训练一个CNN网络-我有约100k种各种植物(1000个类)的图像,并想对ResNet50进行微调以创建一个多类分类器。图片大小各异,我像这样加载它们:
from keras.preprocessing import image
def path_to_tensor(img_path):
# loads RGB image as PIL.Image.Image type
img = image.load_img(img_path, target_size=(IMG_HEIGHT, IMG_HEIGHT))
# convert PIL.Image.Image type to 3D tensor with shape (IMG_HEIGHT, IMG_HEIGHT, 3)
x = image.img_to_array(img)
# convert 3D tensor to 4D tensor with shape (1, IMG_HEIGHT, IMG_HEIGHT, 3) and return 4D tensor
return np.expand_dims(x, axis=0)
def paths_to_tensor(img_paths):
list_of_tensors = [path_to_tensor(img_path) for img_path in img_paths] #can use tqdm(img_paths) for data
return np.vstack(list_of_tensors)enter code here
Run Code Online (Sandbox Code Playgroud)
数据库很大(不适合内存),必须创建自己的生成器才能提供从磁盘读取和扩充的功能。(我知道Keras具有.flow_from_directory()-但我的数据不是以这种方式结构化的-它只是将100k图像与100k元数据文件混合在一起的转储)。我可能应该创建一个脚本来更好地构建它们,而不是创建自己的生成器,但是问题可能出在其他地方。
下面的生成器版本暂时不做任何扩充-只是重新缩放:
def generate_batches_from_train_folder(images_to_read, labels, …
Run Code Online (Sandbox Code Playgroud) 我对 Spark 很陌生,无法让它工作...希望有一种简单的方法可以做到这一点...我想要做的最好由下表描述:(我需要获得“必填”栏)
colA colB colC ref required
1 a1 b1 c1 colA a1
2 a2 b2 c2 colA a2
3 a3 b3 c3 colB b3
4 a4 b4 c4 colB b4
5 a5 b5 c5 colC c5
6 a6 b6 c6 colC c6
Run Code Online (Sandbox Code Playgroud)
上面只是一个例子 - 在真实的例子中我有 >50 列,所以做条件是行不通的......
我知道这可以在 pandas 中轻松完成,使用以下方法:
df['required'] = df.apply(lambda x: x.loc[x.ref], axis=1)
Run Code Online (Sandbox Code Playgroud)
或者
df['required'] = df.lookup(df.index, df.ref)
Run Code Online (Sandbox Code Playgroud)
有什么建议如何在 PySpark 中执行此操作吗?