mirror of
https://github.com/netfun2000/dddd_trainer.git
synced 2026-08-12 21:09:39 +08:00
beta0.1
This commit is contained in:
+2
-2
@@ -36,8 +36,8 @@ class Config(object):
|
||||
"SAVE_CHECKPOINTS_STEP": 2000,
|
||||
"TARGET": {
|
||||
"Accuracy": 0.97,
|
||||
"Epoch": 200,
|
||||
"Cost": 0.005
|
||||
"Epoch": 20,
|
||||
"Cost": 0.05
|
||||
},
|
||||
"LR": 0.01
|
||||
}
|
||||
|
||||
+4
-4
@@ -55,12 +55,10 @@ class CacheData:
|
||||
logger.info("\nChecking labels.txt ...")
|
||||
error_files = set(labels_filename_lines).difference(set(files))
|
||||
logger.info("\nCheck labels.txt end! {} errors!".format(len(error_files)))
|
||||
for ef in error_files:
|
||||
labels_lines.remove(ef)
|
||||
del files
|
||||
self.__collect_data(labels_lines, images_path, is_file=True)
|
||||
self.__collect_data(labels_lines, images_path, error_files, is_file=True)
|
||||
|
||||
def __collect_data(self, lines, base_path, is_file=False):
|
||||
def __collect_data(self, lines, base_path, error_files, is_file=False):
|
||||
labels = []
|
||||
caches = []
|
||||
|
||||
@@ -72,6 +70,8 @@ class CacheData:
|
||||
else:
|
||||
filename = file
|
||||
label = "_".join(filename.split("_")[:-1])
|
||||
if filename in error_files:
|
||||
continue
|
||||
label = label.replace(" ", "")
|
||||
if filename.split('.')[-1] in self.allow_ext:
|
||||
if " " in filename:
|
||||
|
||||
+10
-9
@@ -3,14 +3,16 @@ import os
|
||||
|
||||
import torch
|
||||
import tqdm
|
||||
import numpy as np
|
||||
|
||||
from configs import Config
|
||||
from loguru import logger
|
||||
|
||||
import torchvision
|
||||
from PIL import Image, ImageFile
|
||||
from torch.utils.data import DataLoader, Dataset, TensorDataset
|
||||
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||
|
||||
|
||||
class LoadCache(Dataset):
|
||||
def __init__(self, cache_path: str, path: str, word: bool, image_channel: int, resize: list, charset: list):
|
||||
@@ -48,20 +50,19 @@ class LoadCache(Dataset):
|
||||
else:
|
||||
image_label = [image_label]
|
||||
if self.ImageChannel == 1:
|
||||
mode = torchvision.io.ImageReadMode.GRAY
|
||||
mode = "L"
|
||||
else:
|
||||
mode = torchvision.io.ImageReadMode.RGB
|
||||
image = torchvision.io.read_image(image_path, mode=mode) # shape c, h, w
|
||||
image_shape = image.shape
|
||||
mode = "RGB"
|
||||
image = Image.open(image_path).convert(mode) # shape c, h, w
|
||||
image_shape = image.size
|
||||
image_height = image_shape[1]
|
||||
image_width = image_shape[2]
|
||||
image_width = image_shape[0]
|
||||
width = self.resize[0]
|
||||
height = self.resize[1]
|
||||
if self.resize[0] == -1:
|
||||
image = torchvision.transforms.Resize((height, int(image_width * (height / image_height))))(image)
|
||||
image = image.resize((int(image_width * (height / image_height)), height))
|
||||
else:
|
||||
image = torchvision.transforms.Resize((height, width))(image)
|
||||
image = torchvision.transforms.ToPILImage()(image)
|
||||
image = image.resize((width, height))
|
||||
label = [int(self.charset.index(item)) for item in list(image_label)]
|
||||
return image, label
|
||||
|
||||
|
||||
+3
-1
@@ -71,8 +71,10 @@ class Train:
|
||||
loaders = load_cache.GetLoader(project_name)
|
||||
self.train = loaders.loaders['train']
|
||||
self.val = loaders.loaders['val']
|
||||
del loaders
|
||||
logger.info("\nGet Data Loader End!")
|
||||
|
||||
|
||||
self.loss = 0
|
||||
self.avg_loss = 0
|
||||
self.start_time = time.time()
|
||||
@@ -139,7 +141,7 @@ class Train:
|
||||
self.net.export_onnx(self.net, dummy_input,
|
||||
os.path.join(self.models_path, "{}_{}_{}_{}_{}.onnx".format(
|
||||
self.project_name, str(accuracy), self.epoch, self.step,
|
||||
time.localtime(self.now_time)))
|
||||
time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(self.now_time))))
|
||||
, input_names, output_names, dynamic_ax)
|
||||
with open(os.path.join(self.models_path, "charset.json"), 'w', encoding="utf-8") as f:
|
||||
f.write(json.dumps(self.net.charset, ensure_ascii=False))
|
||||
|
||||
Reference in New Issue
Block a user