Hello - thanks for providing the benchmarking code =)
I've been trying to reproduce the places205 few-shot results. I've followed the various sections of the README's, and I've ran into a few inconsistencies in file names, which I've tried to sensibly resolve, and eventually got everything working (I think) up until the Step 4: Testing SVM stage of the GETTING_STARTED.md
guide: step 4 - here
Here's everything I've done, with possibly relevant inconsistencies in bold:
- Downloaded and renamed places205 in the desired format
- Converted places205 to numpy files
python extra_scripts/create_imagenet_data_files.py --data_source_dir places205 --output_dir places205-processed
- Generated the 5 samples at different
k
values
python extra_scripts/create_places_low_shot_samples.py \
--images_data_file ssl-benchmark-output/places205/train_images.npy \
--targets_data_file ssl-benchmark-output/places205/train_labels.npy \
--output_path ssl-benchmark-output/places205/low_shot/ \
--k_values "1,2,4,8,16,32,64,96" \
--num_samples 5
- I extracted the training and test fetures with the following two commands
# TRAIN
python tools/extract_features.py \
--config_file configs/benchmark_tasks/low_shot_image_classification/places205/resnet50_supervised_low_shot_extract_features.yaml \ --data_type train \
--output_file_prefix trainval \
--output_dir ssl-benchmark-output/extract_features/weights_init \
TEST.PARAMS_FILE https://dl.fbaipublicfiles.com/fair_self_supervision_benchmark/models/resnet50_in1k_supervised.pkl \
TRAIN.DATA_FILE ssl-benchmark-output/places205/train_images_sample4_k1.npy \
TRAIN.LABELS_FILE ssl-benchmark-output/places205/train_labels_sample4_k1.npy
# TEST
python tools/extract_features.py \
--config_file configs/benchmark_tasks/low_shot_image_classification/places205/resnet50_supervised_low_shot_extract_features.yaml \
--data_type test \
--output_file_prefix test \
--output_dir ssl-benchmark-output/extract_features/weights_init \
TEST.PARAMS_FILE https://dl.fbaipublicfiles.com/fair_self_supervision_benchmark/models/resnet50_in1k_supervised.pkl \
TEST.DATA_FILE places205-processed/val_images.npy \
TEST.LABELS_FILE places205-processed/val_labels.npy
- Train the SVM I had to change the
--data_file
and --targets
arg to not have the s0
part in the filepath
python tools/svm/train_svm_low_shot.py \
--data_file ssl-benchmark-output/extract_features/weights_init/trainval_res_conv1_bn_resize_features.npy \
--targets_data_file ssl-benchmark-output/extract_features/weights_init/trainval_res_conv1_bn_resize_targets.npy \
--costs_list "0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1,1.0,10.0,100.0" \
--output_path ssl-benchmark-output/p205_svm_low_shot/svm_conv1/
- Test the SVM I had to change the
--data_file
and --targets
arg to not have the s0
part in the filepath and also set the k_values
and sample_inds
to only work with the first set of features trained in the previous command: doesn't seem to be an option to train them all at once
python tools/svm/test_svm_low_shot.py
--data_file ssl-benchmark-output/extract_features/weights_init/test_res_conv1_bn_resize_features.npy \
--targets_data_file ssl-benchmark-output/extract_features/weights_init/test_res_conv1_bn_resize_targets.npy \
--costs_list "0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1,1.0,10.0,100.0" \
--output_path ssl-benchmark-output/p205_svm_low_shot/svm_conv1/ \
--k_values "4" \
--sample_inds "0"
The first error was:
[INFO: test_svm_low_shot.py: 188]: Namespace(costs_list='0.0000001,0.000001,0.00001,0.0001,0.001,0.01,0.1,1.0,10.0,100.0', data_file='ssl-benchmark-output/extract_features/weights_init/test_res_conv1_bn_resize_features.npy', dataset='voc', generate_json=0, json_targets=None, k_values='4', output_path='ssl-benchmark-output/p205_svm_low_shot/svm_conv1/', sample_inds='1', targets_data_file='ssl-benchmark-output/extract_features/weights_init/test_res_conv1_bn_resize_targets.npy')
[INFO: test_svm_low_shot.py: 80]: Testing svm for k-values: [4] and sample_inds: [0]
[INFO: svm_helper.py: 58]: loading features and targets...
[INFO: svm_helper.py: 63]: Loaded features: (20500, 9216) and targets: (20500, 1)
[INFO: test_svm_low_shot.py: 98]: Testing SVM for costs: [1e-07, 1e-06, 1e-05, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0, 100.0, 0.0625, 0.03125, 0.015625, 0.0078125, 0.00390625, 0.001953125, 0.0009765625, 0.00048828125, 0.000244140625, 0.0001220703125, 6.103515625e-05, 3.0517578125e-05, 1.52587890625e-05, 7.62939453125e-06, 3.814697265625e-06, 1.9073486328125e-06]
[INFO: svm_helper.py: 144]: Testing SVM for classes: range(0, 1)
[INFO: svm_helper.py: 145]: Num classes: 1
[INFO: test_svm_low_shot.py: 125]: Test sample/k_value/cost/cls: 2/4/1e-07/0
Traceback (most recent call last):
File "tools/svm/test_svm_low_shot.py", line 193, in <module>
main()
File "tools/svm/test_svm_low_shot.py", line 189, in main
test_svm_low_shot(opts)
File "tools/svm/test_svm_low_shot.py", line 128, in test_svm_low_shot
with open(model_file, 'rb') as fopen:
FileNotFoundError: [Errno 2] No such file or directory: 'ssl-benchmark-output/p205_svm_low_shot/svm_conv1/cls0_cost1e-07_sample1_k4.pickle'
Looking in ssl-benchmark-output/p205_svm_low_shot/svm_conv1/
that file isn't there, but this one is: cls0_cost1e-07_sample1_k4.pickle
, so I renamed it to cls0_cost1e-07_sample1_k4.pickle
and reran the script, output this time:
[INFO: test_svm_low_shot.py: 80]: Testing svm for k-values: [4] and sample_inds: [0]
[INFO: svm_helper.py: 58]: loading features and targets...
[INFO: svm_helper.py: 63]: Loaded features: (20500, 9216) and targets: (20500, 1)
[INFO: test_svm_low_shot.py: 98]: Testing SVM for costs: [1e-07, 1e-06, 1e-05, 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0, 100.
0, 0.0625, 0.03125, 0.015625, 0.0078125, 0.00390625, 0.001953125, 0.0009765625, 0.00048828125, 0.000244140625, 0.000122070
3125, 6.103515625e-05, 3.0517578125e-05, 1.52587890625e-05, 7.62939453125e-06, 3.814697265625e-06, 1.9073486328125e-06] [INFO: svm_helper.py: 144]: Testing SVM for classes: range(0, 1)
[INFO: svm_helper.py: 145]: Num classes: 1 [INFO: test_svm_low_shot.py: 125]: Test sample/k_value/cost/cls: 1/4/1e-07/0 Traceback (most recent call last): File "tools/svm/test_svm_low_shot.py", line 193, in <module>
main() File "tools/svm/test_svm_low_shot.py", line 189, in main test_svm_low_shot(opts)
File "tools/svm/test_svm_low_shot.py", line 138, in test_svm_low_shot
eval_cls_labels, eval_preds
File "/rscratch/cjrd/dul-project/deepul_proj_2/fair_self_supervision_benchmark/tools/svm/svm_helper.py", line 99, in get
_precision_recall
preds[:, np.newaxis].astype(np.float64)
File "<__array_function__ internals>", line 6, in hstack
File "/rscratch/cjrd/anaconda3/envs/ssl/lib/python3.7/site-packages/numpy/core/shape_base.py", line 345, in hstack
return _nx.concatenate(arrs, 1)
File "<__array_function__ internals>", line 6, in concatenate
ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 2 dimension(s) and the
array at index 1 has 3 dimension(s)
I tried fiddling with the numpy/dimensions of the the given problem, but it just seems to create more problems downstream.
Any help would be very appreciated. Thank you!