我有一组训练图像,其结构如下:
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 577, 443);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
UIManager.setLookAndFeel("com.seaglasslookandfeel.SeaGlassLookAndFeel");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
JPanel panel = new JPanel();
tabbedPane.addTab("New tab", null, panel, null);
JPanel panel_1 = new JPanel();
tabbedPane.addTab("New tab", null, panel_1, null);
JPanel panel_2 = new JPanel();
tabbedPane.addTab("New tab", null, panel_2, null);
.. rest of components.
10个班级。
我正在尝试扩充图像并将其保存到磁盘,但我想保留文件夹结构,所以:
/howler-monkey/
1.jpg
2.jpg
...jpg
/japanese-mcaque
1.jpg
2.jpg
...
似乎我只是用
运行/augmented/
/howler-monkey
aug_1.jpg
aug_2.jpg
/japanese-mcaque
aug_1.jpg
aug_2.jpg
它会将增强的图像转储到trainDataGenerator = ImageDataGenerator(shear_range=0.2, zoom_range=0.2,
horizontal_flip=True, rotation_range=20, width_shift_range=0.2,
height_shift_range=0.2, fill_mode='nearest')
fileIterator = trainDataGenerator.flow_from_directory('{}/training'.format(args.dataset),
save_to_dir='{}/{}'.format(args.dataset, args.output))
i = 0
for image in fileIterator:
if i > 10:
break
文件夹中,但它不会保存目录结构,因此很难用于训练。
如何在扩充图像时保留原始目录结构?
答案 0 :(得分:1)
所以我最终只是使用pathlib
和trainDataGenerator = ImageDataGenerator(shear_range=0.2, zoom_range=0.2,
horizontal_flip=True, rotation_range=20, width_shift_range=0.2,
height_shift_range=0.2)
for path in list_images(args.dataset):
img = cv2.imread(path)
img = img_to_array(img)
img = np.expand_dims(img, axis=0)
pathlib.Path('{}/{}/{}'.format(args.dataset, args.output,
path.split(os.path.sep)[-2])).mkdir(
parents=True, exist_ok=True)
print(path)
total = 0
for image in trainDataGenerator.flow(img, batch_size=1,
save_to_dir='{}/{}/{}'.format(args.dataset, args.output,
path.split(os.path.sep)[-2]), save_format='jpeg'):
print(total)
total += 1
if total == 10:
break
手动创建目录:
args.dataset
其中args.output
是包含训练图像的str,而augmentedImages
是包含declare module 'node-helper-lib' {
import * as SomeThirdParty from 'node-helper-lib';
interface Helper {
new(opt: SomeThirdParty.Options): SomeThirdParty.Type
}
export = Helper;
}
的str。