2
トレーニングデータセットからランダムに10個の画像をテストデータとして選択します。選択したデータをコピー先のパスにコピーするだけであれば動作します。しかし、ソースデータを削除したい場合は、その一部しか削除できません。私はos.remove()とshutil.move()関数の両方を試しましたが、問題は残ります。以下は私のスクリプトです:os.remove()またはshutil.move()がファイルの一部しか移動できないのはなぜですか?
for label in labels:
training_data_path_ch1 = os.path.join(training_data_folder, label, 'ch1')
test_data_path_ch1 = os.path.join(test_data_folder, label, 'ch1')
training_data_path_ch5 = os.path.join(training_data_folder, label, 'ch5')
test_data_path_ch5 = os.path.join(test_data_folder, label, 'ch5')
ch1_imgs = listdir(training_data_path_ch1)
# Randomly select 10 images
ch1_mask = np.random.choice(len(ch1_imgs), 10)
ch1_selected_imgs = [ch1_imgs[i] for i in ch1_mask]
for selected_img in ch1_selected_imgs:
ch1_img_path = os.path.join(training_data_path_ch1, selected_img)
shutil.copy2(ch1_img_path, test_data_path_ch1)
os.remove(ch1_img_path)
print('Successfully move ' + label + ' ch1 images')
そして、実行状態を示す画像を追加します。
実際に画像をコピーしていくつかの画像を削除できますが、すべての画像を削除できないことがわかりますか?
アイデア?私はどんな助けにも感謝します!あなたが潜在的に同じインデックスがどの手段で複数回あなたは、あなたがすでにコピーして削除したファイルをコピーしようとしている(あなたがコピーすることはできません返さ取得している
ch1_mask = np.random.choice(len(ch1_imgs), 10)
:で
ありがとうございます!!!私はこの問題を認識しませんでした。 –