Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PIL for image resizing #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
139 changes: 139 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# OS and Editor stuff
.DS_Store
.vscode

# AWS stuff
*.pem

# Model Binaries
*.pt

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
- h5py=2.7
- pathlib2=2.3
- scipy=0.19.1
- Pillow=8.4.0
- jupyter=1.0.0
- torchvision
- pytorch
- pytorch
73 changes: 59 additions & 14 deletions full-vqa-example.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions utils/extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

import torch
import numpy as np
from scipy.misc import imread, imresize
from PIL import Image
from scipy.misc import imread
from torchvision.models import resnet101

def load_feature_extractor(model_stage=2):
Expand Down Expand Up @@ -70,7 +71,7 @@ def extract_image_feats(img_path, model):
# read in the image and transform it to shape (1, 3, 224, 224)
path = str(img_path) # to handle pathlib
img = imread(path, mode='RGB')
img = imresize(img, (224, 224), interp='bicubic')
img = np.array(Image.fromarray(img).resize((224, 224), resample=Image.BICUBIC))
img = img.transpose(2, 0, 1)[None]

# use ImageNet statistics to transform the data
Expand Down
30 changes: 20 additions & 10 deletions visualize-output.ipynb

Large diffs are not rendered by default.