Skip to content

Commit

Permalink
create dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro.m.fernandez committed Jul 30, 2020
1 parent 8dc68b1 commit d0497bf
Show file tree
Hide file tree
Showing 15 changed files with 155 additions and 47 deletions.
31 changes: 31 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.117.0/containers/docker-existing-dockerfile
{
"name": "PyT Docker FerAtt",

// Sets the run context to one level up instead of the .devcontainer folder.
"context": ".",

// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerFile": "Dockerfile",

// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": null
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [8097],

// Uncomment the next line to run commands after the container is created - for example installing git.
// "postCreateCommand": "apt-get update && apt-get install -y git",

"runArgs": [ "--ipc=host", "--gpus=all"],
"mounts": [ "source=${HOME}.datasets,target=/root/.datasets,type=bind" ],

// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
}
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/__pycache__
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
],
"python.testing.pytestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.unittestEnabled": true
"python.testing.unittestEnabled": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true
}
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu16.04
ARG PYTHON_VERSION=3.7
ARG WITH_TORCHVISION=1

RUN apt-get update && apt-get -y upgrade && apt-get install -y --no-install-recommends \
build-essential \
cmake \
vim \
git \
curl \
ca-certificates \
libgtk2.0-dev \
libjpeg-dev \
libpng-dev && \
rm -rf /var/lib/apt/lists/*

RUN curl -o ~/miniconda.sh -L -O https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b -p /opt/conda && \
rm ~/miniconda.sh && \
/opt/conda/bin/conda install -y python=$PYTHON_VERSION numpy pyyaml scipy ipython mkl mkl-include ninja cython typing && \
/opt/conda/bin/conda install -y -c pytorch magma-cuda100 && \
/opt/conda/bin/conda clean -ya
ENV PATH /opt/conda/bin:$PATH

RUN /opt/conda/bin/conda install pytorch torchvision cudatoolkit=10.1 -c pytorch

WORKDIR /opt
RUN git clone https://github.com/pedrodiamel/pytorchvision.git && cd pytorchvision && python setup.py install

RUN pip install --upgrade pip

RUN apt-get update -y && apt-get upgrade -y && apt-get install -y vim emacs nano htop

# WORKDIR /.datasets
# RUN chmod -R a+w .

WORKDIR /workspace
ADD requirements.txt .
RUN pip install -r requirements.txt
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Installation
$python setup.py install
$pip install -r installation.txt

Docker:

docker build -f "Dockerfile" -t feratt:latest .
./run_docker.sh

### Visualize result with Visdom

We now support Visdom for real-time loss visualization during training!
Expand Down Expand Up @@ -87,4 +92,3 @@ Acknowledgments
------------

Gratefully acknowledge financial support from the Brazilian government agency FACEPE.

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
scikit-image
sklearn
scikit-fmm
h5py
pandas
pandas
scikit-fmm
9 changes: 9 additions & 0 deletions run_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

docker run -ti \
--gpus=all \
--ipc=host \
-v $HOME/.datasets:/root/.datasets \
-v $PWD:/workspace \
-p 8097:8097 \
--name feratt-run feratt:latest \
/bin/bash
6 changes: 1 addition & 5 deletions runs/eval.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash


PATHDATASET='~/.datasets/'
NAMEDATASET='affectnet' #bu3dfe, ferblack, ck, affectnetdark, affectnet, ferp
PROJECT='../out'
Expand All @@ -9,9 +8,8 @@ FILENAME='result.txt'
PATHMODEL='models'
NAMEMODEL='chk000080.pth.tar' #'model_best.pth.tar' #'chk000565.pth.tar'


PROJECTNAME='att_attgmmnet_ferattentiongmm_attloss_adam_affectnetdark_dim64_cvgg13x32_fold0_000'
MODEL=$PROJECT/$PROJECTNAME/$PATHMODEL/$NAMEMODEL
MODEL=$PROJECT/$PROJECTNAME/$PATHMODEL/$NAMEMODEL

python ../eval.py \
--project=$PROJECT \
Expand All @@ -21,5 +19,3 @@ python ../eval.py \
--pathnameout=$PATHNAMEOUT \
--filename=$FILENAME \
--model=$MODEL \


3 changes: 1 addition & 2 deletions runs/represent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PATHNAMEOUT='../out'
FILENAME='result.txt'
PATHMODEL='models'
NAMEMODEL='model_best.pth.tar' #'model_best.pth.tar' #'chk000565.pth.tar'
MODEL=$PROJECT/$PROJECTNAME/$PATHMODEL/$NAMEMODEL
MODEL=$PROJECT/$PROJECTNAME/$PATHMODEL/$NAMEMODEL

python ../represent.py \
--project=$PROJECT \
Expand All @@ -18,4 +18,3 @@ python ../represent.py \
--pathnameout=$PATHNAMEOUT \
--filename=$FILENAME \
--model=$MODEL \

6 changes: 3 additions & 3 deletions runs/train.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NAMEMETHOD='attnet' # attnet, attstnnet, attgmmnet, attgmmstnnet
ARCH='ferattention' # ferattention, ferattentionstn, ferattentiongmm, ferattentiongmmstn
LOSS='attloss'
OPT='adam'
SCHEDULER='plateau' #step, plateau
SCHEDULER='fixed' #fixed, step, plateau
NUMCLASS=8 #6, 7, 8
NUMCHANNELS=3
DIM=32
Expand All @@ -33,8 +33,8 @@ EXP_NAME='feratt_'$NAMEMETHOD'_'$ARCH'_'$LOSS'_'$OPT'_'$NAMEDATASET'_dim'$DIM'_b

rm -rf $PROJECT/$EXP_NAME/$EXP_NAME.log
rm -rf $PROJECT/$EXP_NAME/
mkdir $PROJECT
mkdir $PROJECT/$EXP_NAME
mkdir -p $PROJECT
mkdir -p $PROJECT/$EXP_NAME

#0,1,2,3
CUDA_VISIBLE_DEVICES=0 python ../train.py \
Expand Down
7 changes: 3 additions & 4 deletions runs/train_bu3dfe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NAMEMETHOD='attnet' #attnet, attstnnet, attgmmnet, attgmmstnnet
ARCH='ferattention' #ferattention, ferattentiongmm, ferattentionstn
LOSS='attloss'
OPT='adam'
SCHEDULER='step'
SCHEDULER='fixed'
NUMCLASS=7 #6, 7, 8
NUMCHANNELS=3
DIM=32
Expand All @@ -31,11 +31,10 @@ BACKBONE='preactresnet' #preactresnet, resnet, cvgg

EXP_NAME='feratt_'$NAMEMETHOD'_'$ARCH'_'$LOSS'_'$OPT'_'$NAMEDATASET'_dim'$DIM'_bb'$BACKBONE'_fold'$KFOLD'_000'


rm -rf $PROJECT/$EXP_NAME/$EXP_NAME.log
rm -rf $PROJECT/$EXP_NAME/
mkdir $PROJECT
mkdir $PROJECT/$EXP_NAME
mkdir -p $PROJECT
mkdir -p $PROJECT/$EXP_NAME


CUDA_VISIBLE_DEVICES=0 python ../train.py \
Expand Down
7 changes: 3 additions & 4 deletions runs/train_ck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NAMEMETHOD='attnet' #attnet, attstnnet, attgmmnet, attgmmstnnet
ARCH='ferattention' #ferattention, ferattentiongmm, ferattentionstn
LOSS='attloss'
OPT='adam'
SCHEDULER='step'
SCHEDULER='fixed'
NUMCLASS=8 #6, 7, 8
NUMCHANNELS=3
DIM=32
Expand All @@ -31,11 +31,10 @@ BACKBONE='preactresnet' #preactresnet, resnet, cvgg

EXP_NAME='feratt_'$NAMEMETHOD'_'$ARCH'_'$LOSS'_'$OPT'_'$NAMEDATASET'_dim'$DIM'_bb'$BACKBONE'_fold'$KFOLD'_000'


rm -rf $PROJECT/$EXP_NAME/$EXP_NAME.log
rm -rf $PROJECT/$EXP_NAME/
mkdir $PROJECT
mkdir $PROJECT/$EXP_NAME
mkdir -p $PROJECT
mkdir -p $PROJECT/$EXP_NAME


CUDA_VISIBLE_DEVICES=0 python ../train.py \
Expand Down
5 changes: 2 additions & 3 deletions runs/train_mitosis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ EXP_NAME='mitosis_att_'$NAMEMETHOD'_'$ARCH'_'$LOSS'_'$OPT'_'$NAMEDATASET'_dim'$D

# rm -rf $PROJECT/$EXP_NAME/$EXP_NAME.log
# rm -rf $PROJECT/$EXP_NAME/
# mkdir $PROJECT
# mkdir $PROJECT/$EXP_NAME
# mkdir -p $PROJECT
# mkdir -p $PROJECT/$EXP_NAME


CUDA_VISIBLE_DEVICES=0,1,2,3 python ../train_mitosis.py \
Expand Down Expand Up @@ -63,4 +63,3 @@ $DATA \
--parallel \
--finetuning \
2>&1 | tee -a $PROJECT/$EXP_NAME/$EXP_NAME.log \

38 changes: 20 additions & 18 deletions test/data/test_data_generator.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import unittest
import sys

import os
import sys
import numpy as np
import cv2
import matplotlib.pyplot as plt
import unittest

from pytvision.datasets import imageutl as imutl
from pytvision.transforms import functional as F

sys.path.append('../../')
sys.path.append('../')
from torchlib.transforms.ferrender import Generator
from torchlib.datasets.factory import FactoryDataset
from torchlib.datasets.fersynthetic import SyntheticFaceDataset

import matplotlib.pyplot as plt


def test_dataset_synthetic():

data=FactoryDataset.factory(
pathname='~/.datasets/',
name=FactoryDataset.bu3dfe,
name=FactoryDataset.ck,
subset=FactoryDataset.training,
download=True
)
Expand All @@ -31,7 +33,7 @@ def test_dataset_synthetic():
)

img, mask, label = dataset[ np.random.randint( len(dataset) ) ]
#print( len(dataset) )
print( len(dataset) )

plt.figure()
plt.subplot(121)
Expand All @@ -45,8 +47,8 @@ def test_dataset_synthetic():
def test_dataset_generator():

data=FactoryDataset.factory(
pathname='~/.datasets/',
name=FactoryDataset.bu3dfe,
pathname= os.path.expanduser('~/.datasets/'),
name=FactoryDataset.ck,
subset=FactoryDataset.training,
download=True
)
Expand All @@ -56,7 +58,7 @@ def test_dataset_generator():
img = np.stack((img,img,img),axis=2)

idx=1
pathname = os.path.expanduser( '~/.datasets/photo' )
pathname = os.path.expanduser( '~/.datasets/coco' )
data_back = imutl.imageProvide( pathname, ext='jpg');
back = data_back[ (idx)%len(data_back) ]
back = F.resize_image(back, 640, 1024, resize_mode='crop', interpolate_mode=cv2.INTER_LINEAR);
Expand All @@ -67,18 +69,18 @@ def test_dataset_generator():
print(img.shape, img.max())
print(back.shape, back.max())

image, mask = ren.generate(img, back )
image, image_ilu, mask, h = ren.generate(img, back )
print( image.shape, image.max() )
print( mask.shape, mask.max() )

plt.figure()
plt.subplot(121)
plt.imshow(image.mean(axis=2), cmap='gray' )
plt.subplot(122)
plt.imshow( mask[:,:,0] )
plt.show()
# plt.figure()
# plt.subplot(121)
# plt.imshow(image.mean(axis=2), cmap='gray' )
# plt.subplot(122)
# plt.imshow( mask[:,:,0] )
# plt.show()



# test_dataset_generator()
test_dataset_synthetic()
test_dataset_generator()
# test_dataset_synthetic()
11 changes: 7 additions & 4 deletions test/test_model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from torchlib import models as md
import torch.nn as nn
# python -m unittest test_model.py

import os
import sys

import torch
import torch.nn as nn
import unittest
import sys
import os

sys.path.append('../')
from torchlib import models as md


class TestModel(unittest.TestCase):
Expand Down

0 comments on commit d0497bf

Please sign in to comment.