Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
change default quality from 80 to 95 for bigger and deeper network (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tornadomeet authored and piiswrong committed Dec 9, 2016
1 parent 2829115 commit 29143dd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions example/image-classification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ python tools/im2rec.py --list True --recursive True --train-ratio 0.95 mydata im
```

Then we generate the `.rec` files. We resize the images such that the short edge
is at least 480px and save them with 90/100 quality. We also use 16 threads to
is at least 480px and save them with 95/100 quality. We also use 16 threads to
accelerate the packing.

```bash
python tools/im2rec.py --resize 480 --quality 90 --num-thread 16 mydata img_data
python tools/im2rec.py --resize 480 --quality 95 --num-thread 16 mydata img_data
```

Hints:
Expand Down
4 changes: 2 additions & 2 deletions example/image-classification/data/caltech256.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ mv caltech256-val_train.lst caltech256-val.lst
rm caltech256-val_*

# generate rec files
python ${MX_DIR}/tools/im2rec.py --resize 256 --quality 90 --num-thread 16 caltech256-val 256_ObjectCategories/
python ${MX_DIR}/tools/im2rec.py --resize 256 --quality 90 --num-thread 16 caltech256-train ${TRAIN_DIR}/
python ${MX_DIR}/tools/im2rec.py --resize 256 --quality 95 --num-thread 16 caltech256-val 256_ObjectCategories/
python ${MX_DIR}/tools/im2rec.py --resize 256 --quality 95 --num-thread 16 caltech256-train ${TRAIN_DIR}/

# clean
rm -rf ${TRAIN_DIR} 256_ObjectCategories/
2 changes: 1 addition & 1 deletion python/mxnet/recordio.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def unpack_img(s, iscolor=-1):
img = cv2.imdecode(img, iscolor)
return header, img

def pack_img(header, img, quality=80, img_fmt='.jpg'):
def pack_img(header, img, quality=95, img_fmt='.jpg'):
"""pack an image into MXImageRecord
Parameters
Expand Down
8 changes: 4 additions & 4 deletions tools/im2rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) {
"\tnsplit=NSPLIT[default=1] used for part generation, logically split the image.list to NSPLIT parts by position\n"\
"\tpart=PART[default=0] used for part generation, pack the images from the specific part in image.list\n"\
"\tcenter_crop=CENTER_CROP[default=0] specify whether to crop the center image to make it square.\n"\
"\tquality=QUALITY[default=80] JPEG quality for encoding (1-100, default: 80) or PNG compression for encoding (1-9, default: 3).\n"\
"\tquality=QUALITY[default=95] JPEG quality for encoding (1-100, default: 95) or PNG compression for encoding (1-9, default: 3).\n"\
"\tencoding=ENCODING[default='.jpg'] Encoding type. Can be '.jpg' or '.png'\n"\
"\tinter_method=INTER_METHOD[default=1] NN(0) BILINEAR(1) CUBIC(2) AREA(3) LANCZOS4(4) AUTO(9) RAND(10).\n"\
"\tunchanged=UNCHANGED[default=0] Keep the original image encoding, size and color. If set to 1, it will ignore the others parameters.\n");
Expand All @@ -65,21 +65,21 @@ int main(int argc, char *argv[]) {
int nsplit = 1;
int partid = 0;
int center_crop = 0;
int quality = 80;
int quality = 95;
int color_mode = CV_LOAD_IMAGE_COLOR;
int unchanged = 0;
int inter_method = CV_INTER_LINEAR;
std::string encoding(".jpg");
for (int i = 4; i < argc; ++i) {
char key[128], val[128];
int effct_len = 0;

#ifdef _MSC_VER
effct_len = sscanf_s(argv[i], "%[^=]=%s", key, sizeof(key), val, sizeof(val));
#else
effct_len = sscanf(argv[i], "%[^=]=%s", key, val);
#endif

if (effct_len == 2) {
if (!strcmp(key, "resize")) new_size = atoi(val);
if (!strcmp(key, "label_width")) label_width = atoi(val);
Expand Down
4 changes: 2 additions & 2 deletions tools/im2rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def parse_args():
be packed by default.')
rgroup.add_argument('--center-crop', type=bool, default=False,
help='specify whether to crop the center image to make it rectangular.')
rgroup.add_argument('--quality', type=int, default=80,
rgroup.add_argument('--quality', type=int, default=95,
help='JPEG quality for encoding, 1-100; or PNG compression for encoding, 1-9')
rgroup.add_argument('--num-thread', type=int, default=1,
help='number of thread to use for encoding. order of images will be different\
Expand All @@ -195,7 +195,7 @@ def parse_args():
rgroup.add_argument('--shuffle', default=True, help='If this is set as True, \
im2rec will randomize the image order in <prefix>.lst')
rgroup.add_argument('--pack-label', default=False,
help='Whether to also pack multi dimensional label in the record file')
help='Whether to also pack multi dimensional label in the record file')
args = parser.parse_args()
args.prefix = os.path.abspath(args.prefix)
args.root = os.path.abspath(args.root)
Expand Down

0 comments on commit 29143dd

Please sign in to comment.