TreB1eN / InsightFace_Pytorch

Pytorch0.4.1 codes for InsightFace
MIT License
1.73k stars 423 forks source link

Training #1

Closed tensorboy closed 5 years ago

tensorboy commented 6 years ago

HI, @TreB1eN Thanks for sharing the code of this repo.

I'm just wondering do we have a model training from scratch using this pipeline?

TreB1eN commented 6 years ago

@tensorboy Hi, the pretrained models I provided on section 2 are trained from scratch. If you want to train it by yourself, please refer to scetion 3.4

tensorboy commented 6 years ago

Yeah, I'm training it now. But accuracy is low (0.5) on my side. I also noticed you have some code not uploaded, like prepare_data.py, right?

TreB1eN commented 6 years ago

@tensorboy yes, I forgot to upload it, now it's uploaded. For training, basically we need first transform the origin mxrecord file into jpgs and bcolz files first, I will also provide the requirements later

tensorboy commented 6 years ago

Thanks a lot, I just made this one to read the original mxrecord file:

from pathlib import Path
from torch.utils.data import Dataset, ConcatDataset, DataLoader
from torchvision import transforms as trans
from torchvision.datasets import ImageFolder
import os
import numpy as np
import cv2
import bcolz
import pickle
import torch
import mxnet as mx

import os

save_dir = './faces_emore/imgs'
imgrec = mx.recordio.MXIndexedRecordIO('./faces_emore/train.idx', './faces_emore/train.rec', 'r')
s = imgrec.read_idx(0)
header, _ = mx.recordio.unpack(s)
print(header.label)
imgidx = list(range(1, int(header.label[0])))
seq_identity = range(int(header.label[0]), int(header.label[1]))

id2range = {}
for identity in seq_identity:
    s = imgrec.read_idx(identity)
    header, _ = mx.recordio.unpack(s)
    a, b = int(header.label[0]), int(header.label[1])
    id2range[identity] = (a, b)
print('id2range', len(id2range))
for i in imgidx:

    img_info = imgrec.read_idx(i)
    header, img = mx.recordio.unpack(img_info)
    img = mx.image.imdecode(img).asnumpy()
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
    label = int(header.label)
    image_save_dir = os.path.join(save_dir, str(label))
    if not os.path.exists(image_save_dir):
        os.makedirs(image_save_dir)
    image_save_path = os.path.join(image_save_dir, str(i)+'.png')
    cv2.imwrite(image_save_path, img)
ANDRESHZ commented 1 year ago

Hi @tensorboy , I hope you are having nice results, I am wondering if you finally found a way to tune with your dataset.

Can you share with the community your code?