def trainPCA(dstFolder, BATCH_SIZE = 50):
ipca = IncrementalPCA(n_components=10, batch_size=BATCH_SIZE)
for batch_isomaps_path in glob.glob(os.path.join(dstFolder, "*_isomaps_centered.p")):
batch_num = int(os.path.basename(batch_isomaps_path).split("_")[0])
isomaps = pickle.load(open(batch_isomaps_path, "rb"))
# remove the illumination and count channel
isomaps_just_color = isomaps[:,:,:,1:3]
#flatten to data
X = isomaps_just_color.reshape(isomaps_just_color.shape[0], -1) # ,isomaps_just_color.shape[3])
ipca.partial_fit(X)
with open(os.path.join(dstFolder, "pca.p"), "wb") as file:
pickle.dump(ipca, file)
评论列表
文章目录