Skip to content

Commit 3f0cb12

Browse files
authored
Merge pull request #11 from HaohanWang/dev
Release v0.0.1-beta
2 parents 135116e + 18d32e8 commit 3f0cb12

File tree

645 files changed

+89051
-91823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

645 files changed

+89051
-91823
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/node_modules
2+
**/*.package-lock.json

.gitignore

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
*/.DS_Store
2-
*/__pycache__
3-
*/.idea
4-
front-end/node_modules
5-
front-end/dist
1+
**/.DS_Store
2+
**/__pycache__
3+
**/.idea
4+
**/node_modules
5+
**/dist
66

77

88
# local env files
@@ -15,6 +15,9 @@ yarn-debug.log*
1515
yarn-error.log*
1616
pnpm-debug.log*
1717

18+
back-end/runs
19+
back-end/influence_list
20+
1821
# Editor directories and files
1922
.idea
2023
.vscode
@@ -23,3 +26,4 @@ pnpm-debug.log*
2326
*.njsproj
2427
*.sln
2528
*.sw?
29+
*.pyc

Dockerfile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM paulcccccch/robustar:base-0.0.1
2+
# Default VCUDA is 11.1
3+
ARG VCUDA=11.1
4+
COPY . /Robustar2/
5+
6+
WORKDIR /Robustar2
7+
8+
9+
## Host with lerna: Install global node dependencies
10+
# RUN npm install -g webpack webpack-cli lerna @vue/cli
11+
12+
## Host with NGINX:
13+
RUN sudo apt-get -y install nginx
14+
RUN rm -rf /var/www/html
15+
RUN cp -r /Robustar2/front-end/packages/robustar/dist /var/www/html
16+
17+
# Install PyTorch
18+
RUN ["/bin/bash", "-c", "./scripts/install_pytorch.sh -c $VCUDA"]
19+
20+
# Install frontend libraries
21+
# WORKDIR /Robustar2/front-end
22+
# RUN npm install
23+
# RUN lerna bootstrap
24+
25+
# Build image-editor
26+
# RUN lerna run build:editor
27+
# WORKDIR /Robustar2
28+
29+
CMD ["/bin/bash", "./scripts/start.sh"]
30+

README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
11
# Robustar_implementation
22

3-
#### Contributor
4-
- [Yuhao Zhang](mailto:yhao.zhang98@gmail.com)
5-
- [Leyang Hu](mailto:leonleyanghu@gmail.com)
3+
## To Run Docker
4+
5+
First, run `robustar.sh -m setup -a <version_name>` to pull robustar image.
6+
7+
Then, run `robustar.sh -m run <options> `. For a list of `<options>`, please run `robustar.sh` with no arguments. Make sure you set up the mounting directories and port forwarding correctly.
8+
9+
If at any point you wish to change the setting, please remove the docker container and setup a new one. You can run `docker container ls -a` to see a list of containers, and use `docker container rm <name>` to remove.
10+
11+
Please make sure port 6848 and 6006 on your machine are available.
12+
13+
## Configuration File
14+
You need to pass a config file (default `./configs.json`) to `robustar.sh`. It is a `JSON` file with the following fields:
15+
16+
- **weight_to_load**: The name of the weight file to be loaded. Robustar will display its predictions and attention weights on the given dataset. If not provided or file is not found, but `pre_trained` is set to true, Robustar will try to download a trained image somewhere else.
17+
- **model_arch**: The architecture of the model. Choose from `["resnet-18", "resnet-18-32x32", "resnet-18", "resnet-34", "resnet-50", "resnet-101", "resnet-152", "mobilenet-v2"]`. Make sure this matches what's stored in `weight_to_load`.
18+
]`
19+
- **device**: e.g. `'cpu'`, `'cuda'`, `'cuda:5'`, etc. Robustar uses this device to do both training and inference.
20+
- **pre_trained**: Do we load pre-trained weights? If set to false, `weight_to_load` will be ignored and Robustar will train a model from scratch. Note that the image predictions and focus will be non-sensical in this case.
21+
22+
23+
24+
## Build Docker Image
25+
In front-end directory, run ` lerna run build `.
26+
27+
Then, return back to root directory and run
28+
```
29+
docker build --build-arg VCUDA=<cuda version> .
30+
```
31+
where `<cuda version>` is chosen from `cpu`, `9.2`, `10.2`, `11.1` and `11.3`.
32+
33+
Adjust the tag of the docker image with
34+
```
35+
docker tag <image_id> <user_id>/<repo>:<version>
36+
```
37+
38+
Finally, push onto DockerHub with:
39+
```
40+
docker push <user_id>/<repo>:<version>
41+
```
42+
43+
## Dev setup
44+
45+
See [backend doc](./back-end/README.md) and [frontend doc](./front-end/README.md) for more details
46+
47+
48+
## Notes
49+
### Image URL
50+
For any dataset provided by the user, an `image_url` uniquely identifies an image. An `image_url` looks like `<split>/<image_id>`, i.e. it consists of a string `split` and ae natural number `image_id`, concatenated with a slash `/`. For example, `train/102` stands for the 102th image in the training set, and visiting `http://localhost:8000/image/train/102` gives you the image. Translation between `image_url` and its absolute path is performed at the backend.

back-end/.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
*/.DS_Store
2+
*/__pycache__
3+
*/.idea
4+
*/node_modules
5+
*/dist
6+
7+
8+
# local env files
9+
.env.local
10+
.env.*.local
11+
12+
# Log files
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
pnpm-debug.log*
17+
18+
# Editor directories and files
19+
.idea
20+
.vscode
21+
*.suo
22+
*.ntvs*
23+
*.njsproj
24+
*.sln
25+
*.sw?

back-end/Dockerfile

Lines changed: 0 additions & 6 deletions
This file was deleted.

back-end/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
```
55
cd back-end # If you are not already in this folder
66
pip install -r requirements.txt
7-
python run server.py
7+
python server.py
88
```
99

1010

@@ -21,11 +21,17 @@ https://hub.docker.com/r/cdonglin/robustar
2121

2222
# Dev
2323

24-
Robustar reads from the following directories (absolute path, i.e. `Robustar2` folder is placed immediatly under `/` of your file system)
24+
Robustar reads from the following directories (absolute path, i.e. `Robustar2` folder is placed immediatly under `/` of your file system. Specifically, for linux and MacOS, put the folder under `/` directory. For Windows, put it directly under the volumn your operating system is installed (usually `C:`).
2525

2626
- `/Robuster2/checkpoint_images` for pre-trained weights
27-
- `/Robuster2/dataset/train` for training dataset
27+
- `/Robuster2/dataset/train` for training dataset. Each subfolder under this directory should contain images for a class, i.e. it should follow the format of pytorch `ImageFolder`. Check [here](https://developpaper.com/detailed-explanation-of-the-use-of-imagefolder-in-pytorch/) for more details about `ImageFolder`
28+
- `/Robuster2/dataset/validation` for validation dataset
2829
- `/Robuster2/dataset/test` for test dataset
2930
- `/Robuster2/dataset/paired` for paired dataset
30-
- `/Robuster2/influence_images` for calculated influence
31+
- `/Robuster2/influence_images` for calculated influence images
3132
- `/Robuster2/user-edit.json` for user edit.
33+
- `/Robuster2/configs.json` for server configs. You directly may copy `configs.json` in the repository over.
34+
35+
You can download our example dataset [here](https://drive.google.com/file/d/1DTaPnWV91C9VXZ9JOBz7hoDxfyUXBpUv/view?usp=sharing)
36+
37+
File renamed without changes.

back-end/apis/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# import os
2+
# for module in os.listdir(os.path.dirname(__file__)):
3+
# if module == '__init__.py' or module[-3:] != '.py':
4+
# continue
5+
6+
# __import__("api.{}.*".format(module[:-3]), locals(), globals())
7+
# del module
8+
9+
from .edit import *
10+
from .generate import *
11+
from .image import *
12+
from .predict import *
13+
from .train import *
14+
from .test import *

back-end/apis/edit.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from objects.RServer import RServer
2+
from objects.RResponse import RResponse
3+
from flask import request
4+
from io import BytesIO
5+
import numpy as np
6+
from PIL import Image
7+
import base64
8+
from utils.image_utils import imageURLToPath
9+
from utils.path_utils import get_paired_path
10+
11+
server = RServer.getServer()
12+
app = server.getFlaskApp()
13+
dataManager = server.getDataManager()
14+
15+
@app.route('/edit/<split>/<image_id>', methods=['POST'])
16+
def user_edit(split, image_id):
17+
json_data = request.get_json()
18+
encoded_string = json_data['image'].split(',')[1]
19+
decoded = base64.b64decode(encoded_string)
20+
21+
h = int(json_data['image_height'])
22+
w = int(json_data['image_width'])
23+
with Image.open(BytesIO(decoded)) as img:
24+
25+
img_path = imageURLToPath('{}/{}'.format(split, image_id))
26+
27+
# TODO: Maybe support editing other splits as well? Or not?
28+
if split != 'train':
29+
raise NotImplemented('Currently we only support editing the `train` split!')
30+
paired_img_path = get_paired_path(img_path, dataManager.train_root, dataManager.paired_root)
31+
32+
to_save = img.resize((w, h))
33+
to_save = to_save.convert('RGB') # image comming from canvas is RGBA
34+
35+
to_save.save(paired_img_path)
36+
37+
return RResponse.ok("Success!")
38+
39+
40+
if __name__ == '__main__':
41+
print(RServer)

0 commit comments

Comments
 (0)