小编Eda*_*diz的帖子

如何在python中使用for循环垂直连接1000张图像?

我想垂直连接很多图像。我曾经skimage读取图像然后在每次迭代中io读取图像并将vconcat新图像垂直连接到旧图像上。我的代码的结果没有连接图像,只是组合图像。如何使每次迭代中的每个图像相互垂直连接的任何想法。

我想垂直连接第一个图像和第二个图像

拳头形象

第二张图片

但我得到了这个结果

结果

在此处输入图片说明

任何帮助,将不胜感激。

data=[]
if nSpectogram <3765:
            for k in range (0,21):
                path=io.imread('E:\\wavelet\\spectrograms\\paz05\\'+'spec_'+isPreictal+'_'+str(nSpectogram+1)+'_'+str(k+1)+'.png')
                im_v_array=np.array(im_v)
                data.append(path)
            res=np.concatenate(data)
            plt.imshow(res,cmap='inferno', aspect='auto', interpolation='nearest')

Run Code Online (Sandbox Code Playgroud)

python concat image concatenation scikit-image

6
推荐指数
2
解决办法
966
查看次数

如何在 Keras 中使用 fit_generator() 平衡数据集?

我正在尝试使用 keras 来拟合 CNN 模型来对 2 类数据进行分类。我有不平衡的数据集我想平衡数据。我不知道我可以在model.fit_generator. 我想知道我是否使用class_weight="balanced"model.fit_generator

主要代码

def generate_arrays_for_training(indexPat, paths, start=0, end=100):      
    while True:
        from_=int(len(paths)/100*start)
        to_=int(len(paths)/100*end)
        for i in range(from_, int(to_)):
            f=paths[i]
            x = np.load(PathSpectogramFolder+f) 
            x = np.expand_dims(x, axis=0) 
            
            if('P' in f):
                y = np.repeat([[0,1]],x.shape[0], axis=0)
            else:
                y =np.repeat([[1,0]],x.shape[0], axis=0)
            yield(x,y)   
history=model.fit_generator(generate_arrays_for_training(indexPat, filesPath, end=75), 
                                validation_data=generate_arrays_for_training(indexPat, filesPath, start=75),
                                steps_per_epoch=int((len(filesPath)-int(len(filesPath)/100*25))), 
                                validation_steps=int((len(filesPath)-int(len(filesPath)/100*75))),
                                verbose=2,
                                epochs=15, max_queue_size=2, shuffle=True, callbacks=[callback])

Run Code Online (Sandbox Code Playgroud)

python machine-learning generator deep-learning keras

5
推荐指数
1
解决办法
383
查看次数