├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── curi ├── .gitignore ├── .gitmodules ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── concept_data │ ├── CLEVR_val_scenes.json │ ├── clevr-metadata.json │ ├── clevr-properties.json │ ├── clevr_typed_fol_properties.json │ ├── hyp_to_id.json │ ├── kandinsky-metadata.json │ ├── kandinsky-properties.json │ ├── kandinsky_typed_fol_properties.json │ ├── meta_dataset_properties.sh │ ├── task_id_dict_filtered.json │ └── v2_typed_simple_fol.json ├── data.ipynb ├── data_processing │ ├── clevr_to_curi_format.py │ ├── create_curi_images_tasks.py │ ├── create_curi_tasks.py │ ├── filter_meta_dataset.py │ └── kandinsky_to_curi_format.py ├── dataloaders │ ├── __init__.py │ ├── adhoc_data_loader.py │ ├── build_sound_scene.py │ ├── get_dataloader.py │ ├── utils.py │ └── vocabulary.py ├── docker │ ├── Dockerfile │ └── paths.sh ├── hydra_cfg │ ├── data_files │ │ ├── hypotheses_clevr.yaml │ │ ├── hypotheses_kandinsky.yaml │ │ ├── hypotheses_subset_dc.yaml │ │ └── v2_typed_simple_fol_depth_6_trials_2000000_ban_1_max_scene_id_200.yaml │ ├── experiment.yaml │ ├── experiment_all_cubes_test.yaml │ ├── experiment_all_metal_one_gray_test.yaml │ ├── experiment_confounded.yaml │ ├── experiment_curi_test.yaml │ ├── experiment_curi_train.yaml │ ├── experiment_kp_test.yaml │ ├── experiment_kp_train.yaml │ ├── modality │ │ ├── image.yaml │ │ ├── json.yaml │ │ ├── json_10.yaml │ │ └── json_kp.yaml │ ├── mode │ │ ├── eval.yaml │ │ └── train.yaml │ ├── pooling │ │ ├── concat.yaml │ │ ├── gap.yaml │ │ ├── rel_net.yaml │ │ └── trnsf.yaml │ ├── special_rules │ │ ├── json_concat.yaml │ │ ├── json_gap.yaml │ │ ├── json_rel_net.yaml │ │ ├── json_trnsf.yaml │ │ └── sound_concat.yaml │ └── task │ │ └── adhoc_concepts.yaml ├── hydra_eval.py ├── hydra_qualitative.py ├── hydra_train.py ├── hypothesis_generation │ ├── __init__.py │ ├── hypothesis_utils.py │ ├── prefix_postfix.py │ └── reduce_and_process_hypotheses.py ├── install.sh ├── launch_test_jobs.sh ├── launch_train_eval_jobs.sh ├── losses.py ├── models │ ├── __init__.py │ ├── _evaluator.py │ ├── _map_evaluator.py │ ├── _trainer.py │ ├── audio_resnet.py │ ├── encoders.py │ ├── protonet.py │ ├── simple_lstm_decoder.py │ └── utils.py ├── notebooks │ ├── ahdoc_iclr_numbers.ipynb │ └── visualize_alternate_hypotheses.ipynb ├── paths.sh ├── pick_best_checkpoints.py ├── task_id_dict_dc.json ├── third_party │ ├── __init__.py │ ├── image_utils.py │ ├── mlp.py │ └── relation_network.py └── utils │ ├── __init__.py │ ├── checkpointing.py │ └── visualize.py ├── docs ├── index.html └── static │ ├── css │ ├── bulma-carousel.min.css │ ├── bulma-slider.min.css │ ├── bulma.css.map.txt │ ├── bulma.min.css │ ├── fontawesome.all.min.css │ └── index.css │ ├── images │ ├── counting.png │ ├── favicon.svg │ ├── generalization.png │ ├── interpretability.jpg │ ├── library.png │ └── motivation.jpg │ └── js │ ├── bulma-carousel.js │ ├── bulma-carousel.min.js │ ├── bulma-slider.js │ ├── bulma-slider.min.js │ ├── fontawesome.all.min.js │ └── index.js ├── dreamcoder ├── Dockerfile ├── LICENSE ├── Makefile ├── PBE_Strings_Track │ ├── bikes-long-repeat.sl │ ├── bikes-long.sl │ ├── bikes.sl │ ├── bikes_small.sl │ ├── dr-name-long-repeat.sl │ ├── dr-name-long.sl │ ├── dr-name.sl │ ├── dr-name_small.sl │ ├── firstname-long-repeat.sl │ ├── firstname-long.sl │ ├── firstname.sl │ ├── firstname_small.sl │ ├── initials-long-repeat.sl │ ├── initials-long.sl │ ├── initials.sl │ ├── initials_small.sl │ ├── lastname-long-repeat.sl │ ├── lastname-long.sl │ ├── lastname.sl │ ├── lastname_small.sl │ ├── name-combine-2-long-repeat.sl │ ├── name-combine-2-long.sl │ ├── name-combine-2.sl │ ├── name-combine-2_short.sl │ ├── name-combine-3-long-repeat.sl │ ├── name-combine-3-long.sl │ ├── name-combine-3.sl │ ├── name-combine-3_short.sl │ ├── name-combine-4-long-repeat.sl │ ├── name-combine-4-long.sl │ ├── name-combine-4.sl │ ├── name-combine-4_short.sl │ ├── name-combine-long-repeat.sl │ ├── name-combine-long.sl │ ├── name-combine.sl │ ├── name-combine_short.sl │ ├── phone-1-long-repeat.sl │ ├── phone-1-long.sl │ ├── phone-1.sl │ ├── phone-10-long-repeat.sl │ ├── phone-10-long.sl │ ├── phone-10.sl │ ├── phone-10_short.sl │ ├── phone-1_short.sl │ ├── phone-2-long-repeat.sl │ ├── phone-2-long.sl │ ├── phone-2.sl │ ├── phone-2_short.sl │ ├── phone-3-long-repeat.sl │ ├── phone-3-long.sl │ ├── phone-3.sl │ ├── phone-3_short.sl │ ├── phone-4-long-repeat.sl │ ├── phone-4-long.sl │ ├── phone-4.sl │ ├── phone-4_short.sl │ ├── phone-5-long-repeat.sl │ ├── phone-5-long.sl │ ├── phone-5.sl │ ├── phone-5_short.sl │ ├── phone-6-long-repeat.sl │ ├── phone-6-long.sl │ ├── phone-6.sl │ ├── phone-6_short.sl │ ├── phone-7-long-repeat.sl │ ├── phone-7-long.sl │ ├── phone-7.sl │ ├── phone-7_short.sl │ ├── phone-8-long-repeat.sl │ ├── phone-8-long.sl │ ├── phone-8.sl │ ├── phone-8_short.sl │ ├── phone-9-long-repeat.sl │ ├── phone-9-long.sl │ ├── phone-9.sl │ ├── phone-9_short.sl │ ├── phone-long-repeat.sl │ ├── phone-long.sl │ ├── phone.sl │ ├── phone_short.sl │ ├── reverse-name-long-repeat.sl │ ├── reverse-name-long.sl │ ├── reverse-name.sl │ ├── reverse-name_short.sl │ ├── starexec_description.txt │ ├── univ_1-long-repeat.sl │ ├── univ_1-long.sl │ ├── univ_1.sl │ ├── univ_1_short.sl │ ├── univ_2-long-repeat.sl │ ├── univ_2-long.sl │ ├── univ_2.sl │ ├── univ_2_short.sl │ ├── univ_3-long-repeat.sl │ ├── univ_3-long.sl │ ├── univ_3.sl │ ├── univ_3_short.sl │ ├── univ_4-long-repeat.sl │ ├── univ_4-long.sl │ ├── univ_4.sl │ ├── univ_4_short.sl │ ├── univ_5-long-repeat.sl │ ├── univ_5-long.sl │ ├── univ_5.sl │ ├── univ_5_short.sl │ ├── univ_6-long-repeat.sl │ ├── univ_6-long.sl │ ├── univ_6.sl │ └── univ_6_short.sl ├── Readme.md ├── __init__.py ├── bin │ ├── __init__.py │ ├── analyzeDepth.py │ ├── binutil.py │ ├── clevr.py │ ├── clevr_revise_color_count.py │ ├── clevr_revised.py │ ├── compiledDriver.py │ ├── demoLogo.py │ ├── deprecated │ │ ├── __init__.py │ │ ├── compressionGraph.py │ │ ├── evolution.py │ │ ├── extractDeepcoderDataset.py │ │ ├── python_server.py │ │ └── symbolicRegression.py │ ├── evaluate_test_programs.py │ ├── examineFrontier.py │ ├── graphVersionSizes.py │ ├── graphs.py │ ├── image_robustfill.py │ ├── incr.py │ ├── launch.py │ ├── list.py │ ├── logReports.py │ ├── logo.py │ ├── physics.py │ ├── rational.py │ ├── rbBaseline.py │ ├── regexes.py │ ├── relations.py │ ├── scientificLaws.py │ ├── symmetryBreaking.py │ ├── syntax_robustfill.py │ ├── taskRankGraphs.py │ ├── test_cpus.py │ ├── text.py │ └── tower.py ├── docker-compose.yml ├── dreamcoder │ ├── __init__.py │ ├── compression.py │ ├── deprecated │ │ ├── __init__.py │ │ └── network.py │ ├── differentiation.py │ ├── domains │ │ ├── __init__.py │ │ ├── arithmetic │ │ │ ├── __init__.py │ │ │ └── arithmeticPrimitives.py │ │ ├── clevr │ │ │ ├── main.py │ │ │ └── parse_clevr_tasks.py │ │ ├── clevr_revised │ │ │ └── main.py │ │ ├── clevr_revised_color_count │ │ │ └── main.py │ │ ├── list │ │ │ ├── __init__.py │ │ │ ├── listPrimitives.py │ │ │ ├── main.py │ │ │ └── makeListTasks.py │ │ ├── logo │ │ │ ├── __init__.py │ │ │ ├── logoPrimitives.py │ │ │ ├── main.py │ │ │ └── makeLogoTasks.py │ │ ├── misc │ │ │ ├── RobustFillPrimitives.py │ │ │ ├── __init__.py │ │ │ ├── algolispPrimitives.py │ │ │ ├── deepcoderPrimitives.py │ │ │ └── napsPrimitives.py │ │ ├── regex │ │ │ ├── __init__.py │ │ │ ├── groundtruthRegexes.py │ │ │ ├── main.py │ │ │ ├── makeRegexTasks.py │ │ │ └── regexPrimitives.py │ │ ├── relation │ │ │ ├── generate_clause.py │ │ │ ├── generate_tasks.py │ │ │ ├── main.py │ │ │ ├── parse_relation_tasks.py │ │ │ └── relation_primitives.py │ │ ├── text │ │ │ ├── __init__.py │ │ │ ├── main.py │ │ │ ├── makeTextTasks.py │ │ │ └── textPrimitives.py │ │ └── tower │ │ │ ├── __init__.py │ │ │ ├── main.py │ │ │ ├── makeTowerTasks.py │ │ │ ├── towerPrimitives.py │ │ │ └── tower_common.py │ ├── dreamcoder.py │ ├── dreaming.py │ ├── ec.py │ ├── enumeration.py │ ├── fragmentGrammar.py │ ├── fragmentUtilities.py │ ├── frontier.py │ ├── grammar.py │ ├── likelihoodModel.py │ ├── primitiveGraph.py │ ├── primitiveGraphAdaption.py │ ├── program.py │ ├── recognition.py │ ├── task.py │ ├── taskBatcher.py │ ├── type.py │ ├── utilities.py │ └── vs.py ├── evaluation │ ├── collect_solved_tasks.ipynb │ ├── hyp_to_id.json │ ├── task_id_dict_dc.json │ ├── test_programs_all_cubes.ipynb │ ├── test_programs_curi.ipynb │ ├── test_programs_curi_revised.ipynb │ └── test_programs_kandinsky.ipynb ├── evaluation_script.sh ├── evaluation_script_all_cube.sh ├── evaluation_script_all_metal_one_gray.sh ├── evaluation_script_revised_color_count.sh ├── failures │ └── .dummy ├── official_experiments ├── official_figures ├── prototypical-networks │ ├── .gitignore │ ├── ocaml_client.ml │ ├── protonet_score.py │ ├── protonet_server.py │ ├── protonets │ │ ├── __init__.py │ │ ├── engine.py │ │ ├── models │ │ │ ├── __init__.py │ │ │ ├── factory.py │ │ │ ├── few_shot.py │ │ │ └── utils.py │ │ └── utils │ │ │ ├── __init__.py │ │ │ ├── data.py │ │ │ ├── log.py │ │ │ └── model.py │ ├── results-OM │ │ ├── best_model.pt │ │ ├── opt.json │ │ └── trace.txt │ ├── run_train.py │ └── scripts │ │ ├── __init__.py │ │ ├── predict │ │ └── few_shot │ │ │ ├── eval.py │ │ │ └── run_eval.py │ │ └── train │ │ ├── __init__.py │ │ └── few_shot │ │ ├── run_train.py │ │ ├── run_trainval.py │ │ ├── train.py │ │ └── trainval.py ├── requirements.txt ├── revising │ ├── clevr_revise_color_count_result.py │ ├── clevr_revise_experiments.ipynb │ └── create_revising_task.ipynb ├── run_eval.sh ├── run_eval_kand.sh ├── run_eval_revised.sh ├── run_experiment.sh ├── run_experiment_color_count.sh ├── run_experiment_confounded.sh ├── run_kandinsky.sh ├── runtests ├── rust_compressor │ ├── Cargo.lock │ ├── Cargo.toml │ ├── Makefile │ ├── example_input.json │ ├── rust_compressor │ └── src │ │ ├── main.rs │ │ └── vs.rs ├── singularity ├── solvers │ ├── CachingTable.ml │ ├── Dreaming.ml │ ├── EC.ml │ ├── Euclid.ml │ ├── FastType.ml │ ├── Helmholtz.ml │ ├── Makefile │ ├── PolyValue.ml │ ├── TikZ.ml │ ├── cache_pb.ml │ ├── cache_pb.mli │ ├── cache_types.ml │ ├── cache_types.mli │ ├── clever.ml │ ├── client.ml │ ├── color.ml │ ├── combinator.ml │ ├── compression.ml │ ├── differentiation.ml │ ├── enumeration.ml │ ├── funarray.ml │ ├── funarray.mli │ ├── geomDrawFile.ml │ ├── geomDrawLambdaString.ml │ ├── geomGenerate.ml │ ├── geomLib │ │ ├── Generator.ml │ │ ├── Interpreter.ml │ │ ├── Plotter.ml │ │ ├── Plumbing.ml │ │ ├── Renderer.ml │ │ ├── Utils2.ml │ │ ├── geomLexer.mll │ │ ├── geomParser.mly │ │ ├── jbuild │ │ ├── lambdaLexer.mll │ │ └── lambdaParser.mly │ ├── geomTest.ml │ ├── grammar.ml │ ├── heap_search.ml │ ├── jbuild │ ├── karel.ml │ ├── list_synthesizer.ml │ ├── logoDrawString.ml │ ├── logoLib │ │ ├── Colors.ml │ │ ├── VGWrapper.ml │ │ ├── jbuild │ │ └── logoInterpreter.ml │ ├── logoSequenceString.ml │ ├── logoTest.ml │ ├── parallel.ml │ ├── parser.ml │ ├── physics.ml │ ├── polynomial.ml │ ├── pregex.ml │ ├── probabilistic_grammar.ml │ ├── program.ml │ ├── protonet-tester.ml │ ├── recognition.ml │ ├── sfg.ml │ ├── solver.ml │ ├── string_transformation.ml │ ├── task.ml │ ├── timeout.ml │ ├── tower.ml │ ├── turtle.ml │ ├── type.ml │ ├── utils.ml │ ├── versionDemo.ml │ ├── versions.ml │ └── vs.ml ├── taskRankGraphs └── tests │ ├── README.md │ ├── __init__.py │ ├── integration │ └── runtests.sh │ ├── resources │ └── kellis_list_exp.pickle │ ├── test.sh │ ├── test_compression.py │ ├── test_dreamcoder.py │ ├── test_dreaming.py │ ├── test_enumeration.py │ ├── test_fragmentGrammar.py │ ├── test_list.py │ ├── test_logo.py │ ├── test_recognition.py │ ├── test_regexes.py │ ├── test_symmetryBreaking.py │ ├── test_text.py │ └── test_tower.py ├── figures ├── all-cubes.jpg ├── all-metal-one-gray.jpg ├── kandinsky.jpg └── overview.png ├── kandinsky ├── .gitignore ├── README.md ├── __init__.py ├── generate.sh ├── generate_patterns.py ├── requirements.txt └── src │ ├── __init__.py │ ├── generate_tasks.py │ ├── kp │ ├── ClauseBasedKandinskyFigure.py │ ├── KandinskyCaptions.py │ ├── KandinskyTruth.py │ ├── KandinskyUniverse.py │ ├── NumbersKandinskyFigure.py │ ├── RandomKandinskyFigure.py │ ├── SameColorSameShape.py │ ├── SameConcept.py │ ├── ShapeOnShapes.py │ ├── SimpleObjectAndShape.py │ ├── __init__.py │ └── generate_task_clauses.py │ ├── kpgen_random.py │ ├── map │ ├── __init__.py │ ├── categories.json │ ├── class_combinations.py │ ├── class_id_to_name.json │ ├── class_name_to_id.json │ ├── concept_categories.json │ └── concept_relation_categories.json │ └── pix2seq_shortcut.py └── pix2seq ├── .gitignore ├── Dockerfile ├── README.md ├── __init__.py ├── convert_to_dreamcoder.py ├── datasets ├── __init__.py ├── clevr.py ├── coco.py ├── coco_eval.py ├── create_coco_style_annotations.py └── transforms.py ├── docker-compose.yaml ├── engine.py ├── main.py ├── playground ├── __init__.py └── pix2seq │ ├── __init__.py │ ├── attention_layer.py │ ├── backbone.py │ ├── pix2seq.py │ ├── position_encoding.py │ └── transformer.py ├── requirements.txt ├── tox.ini ├── train.sh ├── use_model_clevr.py ├── use_model_kandinsky.py ├── util ├── __init__.py ├── box_ops.py └── misc.py └── validate.py /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pth filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Antonia Wüst 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /curi/.gitignore: -------------------------------------------------------------------------------- 1 | # Gitignore 2 | 3 | # Reject hidden files 4 | ._* 5 | *.out 6 | datasets/* 7 | outputs/* 8 | *.pyc 9 | .ipynb_checkpoints/abstraction_model-Copy1-checkpoint.ipynb 10 | .ipynb_checkpoints/abstraction_model-checkpoint.ipynb 11 | __pycache__/* 12 | scenes_* 13 | performance_* 14 | concept_data/typed_simple_fol_depth_40_rejection_sample_trials_100000.json 15 | concept_data/typed_simple_fol_depth_40_rejection_sample_trials_100000.pkl 16 | hypothesis_generation/__pycache__/* 17 | concept_data/grammar_expander_typed_simple_fol_depth_40_ordinal_size.pkl 18 | results_dump.pkl 19 | concept_data/typed_simple_fol_clevr-properties.pkl 20 | concept_data/typed_simple_fol_depth_30_trials_400000.pkl 21 | concept_data/v1_typed_simple_fol_clevr-properties.pkl 22 | notebooks/.ipynb_checkpoints/Untitled-checkpoint.ipynb 23 | concept_data/temp_data/v1_typed_simple_fol_clevr_typed_fol_properties.pkl 24 | concept_data/temp_data/v2_typed_simple_fol_clevr_typed_fol_properties.pkl 25 | notebooks/hypothtesis_analysis.ipynb 26 | notebooks/Untitled.ipynb 27 | notebooks/.ipynb_checkpoints/hypothtesis_analysis-checkpoint.ipynb 28 | slurm-17729056.out 29 | log_test/* 30 | env/* 31 | notebooks/create_folder_hypothesis_and_json.ipynb 32 | notebooks/.ipynb_checkpoints/create_folder_hypothesis_and_json-checkpoint.ipynb 33 | notebooks/1.png 34 | notebooks/2.png 35 | notebooks/3.png 36 | notebooks/csv_download.csv 37 | notebooks/structured_splits.ipynb 38 | notebooks/visualize_meta_dataset.ipynb 39 | notebooks/*.png 40 | notebooks/.ipynb_checkpoints/* 41 | release/* 42 | runs/* 43 | 44 | curi_release/* 45 | curi_tasks/* 46 | curi_tasks_support/* 47 | dc_tasks/* 48 | dc_tasks_test/* 49 | None/* 50 | runs/* -------------------------------------------------------------------------------- /curi/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "clevr-dataset-gen"] 2 | path = clevr-dataset-gen 3 | url = https://github.com/facebookresearch/clevr-dataset-gen 4 | -------------------------------------------------------------------------------- /curi/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to productive_concept_learning 2 | We want to make contributing to this project as easy and transparent as 3 | possible. 4 | 5 | ## Pull Requests 6 | We actively welcome your pull requests. 7 | 8 | 1. Fork the repo and create your branch from `master`. 9 | 2. If you've added code that should be tested, add tests. 10 | 3. If you've changed APIs, update the documentation. 11 | 4. Ensure the test suite passes. 12 | 5. Make sure your code lints. 13 | 6. If you haven't already, complete the Contributor License Agreement ("CLA"). 14 | 15 | ## Contributor License Agreement ("CLA") 16 | In order to accept your pull request, we need you to submit a CLA. You only need 17 | to do this once to work on any of Facebook's open source projects. 18 | 19 | Complete your CLA here: 20 | 21 | ## Issues 22 | We use GitHub issues to track public bugs. Please ensure your description is 23 | clear and has sufficient instructions to be able to reproduce the issue. 24 | 25 | Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe 26 | disclosure of security bugs. In those cases, please go through the process 27 | outlined on that page and do not file a public issue. 28 | 29 | ## Coding Style 30 | * 4 spaces for indentation rather than tabs 31 | * 80 character line length 32 | 33 | ## License 34 | By contributing to __________, you agree that your contributions will be licensed 35 | under the LICENSE file in the root directory of this source tree. -------------------------------------------------------------------------------- /curi/concept_data/clevr-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "image_size_x": 480, 3 | "image_size_y": 320, 4 | "image_size_z": 16, 5 | "max_object_size": 0.7, 6 | "sizes": { 7 | "large": 0.7, 8 | "small": 0.35 9 | }, 10 | "dimensions_to_idx": { 11 | "x": 0, 12 | "y": 1, 13 | "z": 2 14 | } 15 | } -------------------------------------------------------------------------------- /curi/concept_data/clevr-properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "shapes": { 3 | "cube": "SmoothCube_v2", 4 | "sphere": "Sphere", 5 | "cylinder": "SmoothCylinder" 6 | }, 7 | "colors": { 8 | "gray": [87, 87, 87], 9 | "red": [173, 35, 35], 10 | "blue": [42, 75, 215], 11 | "green": [29, 105, 20], 12 | "brown": [129, 74, 25], 13 | "purple": [129, 38, 192], 14 | "cyan": [41, 208, 208], 15 | "yellow": [255, 238, 51] 16 | }, 17 | "materials": { 18 | "rubber": "Rubber", 19 | "metal": "MyMetal" 20 | }, 21 | "sizes": { 22 | "large": 0.7, 23 | "small": 0.35 24 | } 25 | } -------------------------------------------------------------------------------- /curi/concept_data/clevr_typed_fol_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v0.2", 3 | "properties": { 4 | "shapes": { 5 | "cube": "SmoothCube_v2", 6 | "sphere": "Sphere", 7 | "cylinder": "SmoothCylinder" 8 | }, 9 | "colors": { 10 | "gray": [ 11 | 87, 12 | 87, 13 | 87 14 | ], 15 | "red": [ 16 | 173, 17 | 35, 18 | 35 19 | ], 20 | "blue": [ 21 | 42, 22 | 75, 23 | 215 24 | ], 25 | "green": [ 26 | 29, 27 | 105, 28 | 20 29 | ], 30 | "brown": [ 31 | 129, 32 | 74, 33 | 25 34 | ], 35 | "purple": [ 36 | 129, 37 | 38, 38 | 192 39 | ], 40 | "cyan": [ 41 | 41, 42 | 208, 43 | 208 44 | ], 45 | "yellow": [ 46 | 255, 47 | 238, 48 | 51 49 | ] 50 | }, 51 | "materials": { 52 | "rubber": "Rubber", 53 | "metal": "MyMetal" 54 | }, 55 | "sizes": { 56 | "large": 0.7, 57 | "small": 0.35 58 | } 59 | }, 60 | "metadata": { 61 | "image_size": { 62 | "x": 240, 63 | "y": 160, 64 | "z": 16 65 | }, 66 | "max_rotation": 360, 67 | "min_objects": 2, 68 | "max_objects": 10, 69 | "max_object_size": 0.7, 70 | "sizes": { 71 | "large": 0.7, 72 | "small": 0.35 73 | }, 74 | "dimensions_to_idx": { 75 | "x": 0, 76 | "y": 1, 77 | "z": 2 78 | }, 79 | "location_bins": { 80 | "x": 8, 81 | "y": 8, 82 | "z": 8 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /curi/concept_data/kandinsky-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "image_size_x": 160, 3 | "image_size_y": 240, 4 | "image_size_z": 16, 5 | "max_object_size": 0.7, 6 | "sizes": { 7 | "large": 0.7, 8 | "medium": 0.5, 9 | "small": 0.35 10 | }, 11 | "dimensions_to_idx": { 12 | "x": 0, 13 | "y": 1, 14 | "z": 2 15 | } 16 | } -------------------------------------------------------------------------------- /curi/concept_data/kandinsky-properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "shapes": { 3 | "square": "square", 4 | "circle": "circle", 5 | "triangle": "triangle" 6 | }, 7 | "colors": { 8 | "red": [ 9 | 173, 10 | 35, 11 | 35 12 | ], 13 | "blue": [ 14 | 42, 15 | 75, 16 | 215 17 | ], 18 | "yellow": [ 19 | 255, 20 | 238, 21 | 51 22 | ] 23 | }, 24 | "sizes": { 25 | "small": 0, 26 | "medium": 1, 27 | "large": 2 28 | } 29 | } -------------------------------------------------------------------------------- /curi/concept_data/kandinsky_typed_fol_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v0.2", 3 | "properties": { 4 | "shapes": { 5 | "square": "square", 6 | "circle": "circle", 7 | "triangle": "triangle" 8 | }, 9 | "colors": { 10 | "red": [ 11 | 173, 12 | 35, 13 | 35 14 | ], 15 | "blue": [ 16 | 42, 17 | 75, 18 | 215 19 | ], 20 | "yellow": [ 21 | 255, 22 | 238, 23 | 51 24 | ] 25 | }, 26 | "sizes": { 27 | "small": 0, 28 | "medium": 1, 29 | "large": 2 30 | } 31 | }, 32 | "metadata": { 33 | "image_size": { 34 | "x": 240, 35 | "y": 160, 36 | "z": 16 37 | }, 38 | "max_rotation": 360, 39 | "min_objects": 2, 40 | "max_objects": 6, 41 | "max_object_size": 0.7, 42 | "sizes": { 43 | "large": 0.7, 44 | "small": 0.35 45 | }, 46 | "dimensions_to_idx": { 47 | "x": 0, 48 | "y": 1 49 | }, 50 | "location_bins": { 51 | "x": 8, 52 | "y": 8, 53 | "z": 8 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /curi/concept_data/meta_dataset_properties.sh: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. 2 | # All rights reserved. 3 | # 4 | # This source code is licensed under the license found in the 5 | # LICENSE file in the root directory of this source tree. 6 | # Meta-learning dataset properties 7 | # 8 | # Provides the paths relevant to the meta-dataset generation code 9 | OUTPUT_DATASET_PATH="/checkpoint/ramav/adhoc_concept_data/" 10 | RAW_IMAGE_DATA_PATH="adhoc_images_slurm_v0.2" 11 | 12 | # 13 | DATASET_PROPERTIES="clevr_typed_fol_properties" 14 | GRAMMAR_TYPE="v2_typed_simple_fol" 15 | MAX_RECURSION_DEPTH=6 16 | NUM_HYPOTHESES=2000000 17 | BAN_STRINGS_WITH_SAME_ARGS=1 18 | MAX_SCENE_FILE_ID_FOR_EXEC=200 19 | RAW_DATASET_NUM_IMAGES=5000000 20 | META_DATASET_TRAIN_SIZE=500000 21 | 22 | META_DATASET_NAME=$(cat < 1: 22 | eprint( 23 | "(compiled driver warning: SLOW) Compiled driver unpacked the message in time", 24 | dt, 25 | ) 26 | 27 | response = (False, None) 28 | try: 29 | start = time.time() 30 | f = request["function"] 31 | result = f(*request["arguments"], **request["keywordArguments"]) 32 | response = (True, result) 33 | except Exception as e: 34 | eprint("Exception thrown in pypy process for %s:" % f.__name__) 35 | sys.stderr.write(traceback.format_exc()) 36 | sys.stderr.flush() 37 | finally: 38 | start = time.time() 39 | pickle.dump(response, sys.stdout.buffer) 40 | dt = time.time() - start 41 | if dt > 1: 42 | eprint( 43 | "(compiled driver warning: SLOW) Compiled driver packed the message in time", 44 | dt, 45 | ) 46 | -------------------------------------------------------------------------------- /dreamcoder/bin/demoLogo.py: -------------------------------------------------------------------------------- 1 | try: 2 | import binutil # required to import from dreamcoder modules 3 | except ModuleNotFoundError: 4 | import bin.binutil # alt import if called as module 5 | 6 | from dreamcoder.domains.logo.makeLogoTasks import demoLogoTasks 7 | 8 | if __name__ == "__main__": 9 | demoLogoTasks() 10 | -------------------------------------------------------------------------------- /dreamcoder/bin/deprecated/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/bin/deprecated/__init__.py -------------------------------------------------------------------------------- /dreamcoder/bin/deprecated/compressionGraph.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deprecated compressionGraph.py module. This file only exists to support backwards-compatibility 3 | with old pickle files. See bin/__init__.py for more information. 4 | """ 5 | -------------------------------------------------------------------------------- /dreamcoder/bin/deprecated/evolution.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deprecated evolution.py module. This file only exists to support backwards-compatibility 3 | with old pickle files. See bin/__init__.py for more information. 4 | """ 5 | -------------------------------------------------------------------------------- /dreamcoder/bin/deprecated/extractDeepcoderDataset.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deprecated extractDeepcoderDataset.py module. This file only exists to support backwards-compatibility 3 | with old pickle files. See bin/__init__.py for more information. 4 | """ 5 | -------------------------------------------------------------------------------- /dreamcoder/bin/deprecated/python_server.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deprecated python_server.py module. This file only exists to support backwards-compatibility 3 | with old pickle files. See bin/__init__.py for more information. 4 | """ 5 | -------------------------------------------------------------------------------- /dreamcoder/bin/deprecated/symbolicRegression.py: -------------------------------------------------------------------------------- 1 | """ 2 | Deprecated symbolicRegression.py module. This file only exists to support backwards-compatibility 3 | with old pickle files. See bin/__init__.py for more information. 4 | """ 5 | -------------------------------------------------------------------------------- /dreamcoder/bin/list.py: -------------------------------------------------------------------------------- 1 | try: 2 | import binutil # required to import from dreamcoder modules 3 | except ModuleNotFoundError: 4 | import bin.binutil # alt import if called as module 5 | 6 | from dreamcoder.domains.list.main import list_options, main 7 | from dreamcoder.dreamcoder import commandlineArguments 8 | from dreamcoder.utilities import numberOfCPUs 9 | 10 | if __name__ == "__main__": 11 | args = commandlineArguments( 12 | enumerationTimeout=10, 13 | activation="tanh", 14 | iterations=10, 15 | recognitionTimeout=3600, 16 | a=3, 17 | maximumFrontier=10, 18 | topK=2, 19 | pseudoCounts=30.0, 20 | helmholtzRatio=0.5, 21 | structurePenalty=1.0, 22 | CPUs=numberOfCPUs(), 23 | extras=list_options, 24 | ) 25 | main(args) 26 | -------------------------------------------------------------------------------- /dreamcoder/bin/logo.py: -------------------------------------------------------------------------------- 1 | try: 2 | import binutil # required to import from dreamcoder modules 3 | except ModuleNotFoundError: 4 | import bin.binutil # alt import if called as module 5 | 6 | from dreamcoder.domains.logo.main import LogoFeatureCNN, list_options, main 7 | from dreamcoder.dreamcoder import commandlineArguments 8 | from dreamcoder.utilities import numberOfCPUs 9 | 10 | if __name__ == "__main__": 11 | args = commandlineArguments( 12 | structurePenalty=1.5, 13 | recognitionTimeout=3600, 14 | a=3, 15 | topK=2, 16 | iterations=10, 17 | useRecognitionModel=True, 18 | helmholtzRatio=0.5, 19 | featureExtractor=LogoFeatureCNN, 20 | maximumFrontier=5, 21 | CPUs=numberOfCPUs(), 22 | pseudoCounts=30.0, 23 | activation="tanh", 24 | extras=list_options, 25 | ) 26 | main(args) 27 | -------------------------------------------------------------------------------- /dreamcoder/bin/regexes.py: -------------------------------------------------------------------------------- 1 | try: 2 | import binutil # required to import from dreamcoder modules 3 | except ModuleNotFoundError: 4 | import bin.binutil # alt import if called as module 5 | 6 | from dreamcoder.domains.regex.main import main, regex_options 7 | from dreamcoder.dreamcoder import commandlineArguments 8 | from dreamcoder.utilities import numberOfCPUs 9 | 10 | if __name__ == "__main__": 11 | args = commandlineArguments( 12 | activation="relu", 13 | iterations=10, 14 | a=3, 15 | maximumFrontier=5, 16 | topK=2, 17 | pseudoCounts=30.0, # try 1 0.1 would make prior uniform 18 | helmholtzRatio=0.5, 19 | structurePenalty=1.0, # try 20 | CPUs=numberOfCPUs(), 21 | extras=regex_options, 22 | enumerationTimeout=20 23 | ) 24 | main(args) 25 | -------------------------------------------------------------------------------- /dreamcoder/bin/relations.py: -------------------------------------------------------------------------------- 1 | try: 2 | import binutil # required to import from dreamcoder modules 3 | except ModuleNotFoundError: 4 | import bin.binutil # alt import if called as module 5 | 6 | import datetime 7 | import os 8 | import random 9 | 10 | import torch 11 | 12 | from dreamcoder.domains.relation.main import main 13 | 14 | 15 | from dreamcoder.domains.list.main import LearnedFeatureExtractor 16 | from dreamcoder.ec import commandlineArguments, ecIterator 17 | from dreamcoder.grammar import Grammar 18 | from dreamcoder.program import * 19 | from dreamcoder.task import Task 20 | from dreamcoder.type import arrow, tint 21 | from dreamcoder.utilities import numberOfCPUs 22 | 23 | 24 | if __name__ == "__main__": 25 | # Set recursion limit higher for pickle 26 | sys.setrecursionlimit(10000) 27 | 28 | args = commandlineArguments( 29 | enumerationTimeout=720, 30 | activation="tanh", 31 | iterations=15, 32 | recognitionTimeout=3600, 33 | a=3, 34 | maximumFrontier=5, 35 | topK=2, 36 | pseudoCounts=30.0, 37 | helmholtzRatio=0.5, 38 | structurePenalty=1.5, 39 | CPUs=96, 40 | featureExtractor=LearnedFeatureExtractor, 41 | biasOptimal=True, 42 | contextual=True, 43 | auxiliary=True, 44 | taskReranker="unsolved", 45 | ) 46 | 47 | # start timing 48 | start_time = datetime.datetime.now() 49 | eval = args.pop("eval") 50 | if eval == 0: 51 | _ = args.pop("test_idx") 52 | main(args, eval=False) 53 | else: 54 | _ = args.pop("test_idx") 55 | main(args, eval=True) 56 | # end timing 57 | end_time = datetime.datetime.now() 58 | print("Total time taken: {}".format(end_time - start_time)) 59 | -------------------------------------------------------------------------------- /dreamcoder/bin/symmetryBreaking.py: -------------------------------------------------------------------------------- 1 | try: 2 | import binutil # required to import from dreamcoder modules 3 | except ModuleNotFoundError: 4 | import bin.binutil # alt import if called as module 5 | 6 | from dreamcoder.dreaming import backgroundHelmholtzEnumeration 7 | from dreamcoder.grammar import Grammar 8 | from dreamcoder.program import Program 9 | from dreamcoder.recognition import DummyFeatureExtractor, RecognitionModel 10 | from dreamcoder.task import Task 11 | from dreamcoder.type import arrow, tint 12 | from dreamcoder.utilities import eprint 13 | 14 | 15 | def main(): 16 | trainingTimeout = 600 17 | rt = arrow(tint, tint) 18 | g = Grammar.uniform([Program.parse(p) for p in ["1", "0", "+"]]) 19 | tasks = [Task("dummy", rt, [(tuple([n]), 9) for n in range(3)])] 20 | hf = backgroundHelmholtzEnumeration(tasks, g, 60, evaluationTimeout=0.001) 21 | hf = hf() 22 | f = DummyFeatureExtractor(tasks) 23 | for contextual in [True, False]: 24 | for trainingSource in ["random", "enumerated"]: 25 | eprint("Training contextual =", contextual, "w/", trainingSource, "data") 26 | r = RecognitionModel(f, g, hidden=[], contextual=contextual) 27 | r.train( 28 | [], 29 | helmholtzFrontiers=hf if trainingSource == "enumerated" else [], 30 | helmholtzRatio=1.0, 31 | defaultRequest=rt, 32 | timeout=trainingTimeout, 33 | ) 34 | cg = r.grammarOfTask(tasks[0]).untorch() 35 | eprint(cg) 36 | eprint("Samples from recognition model:") 37 | N = 50 38 | for _ in range(N): 39 | eprint(cg.sample(rt, maximumDepth=20)) 40 | eprint() 41 | 42 | eprint("Samples from generative model:") 43 | for _ in range(N): 44 | eprint(g.sample(rt, maximumDepth=20)) 45 | 46 | 47 | if __name__ == "__main__": 48 | main() 49 | -------------------------------------------------------------------------------- /dreamcoder/bin/test_cpus.py: -------------------------------------------------------------------------------- 1 | import multiprocessing 2 | 3 | 4 | def worker_function(index): 5 | result = 0 6 | for _ in range(1000000): # Some computation task for testing purposes 7 | result += 1 8 | print(f"Worker {index} result: {result}") 9 | 10 | 11 | if __name__ == "__main__": 12 | num_cpus = 10 13 | processes = [] 14 | 15 | for i in range(num_cpus): 16 | process = multiprocessing.Process(target=worker_function, args=(i,)) 17 | processes.append(process) 18 | 19 | # Start all processes 20 | for process in processes: 21 | process.start() 22 | 23 | # Wait for all processes to finish 24 | for process in processes: 25 | process.join() 26 | 27 | print("All processes have finished.") 28 | -------------------------------------------------------------------------------- /dreamcoder/bin/text.py: -------------------------------------------------------------------------------- 1 | try: 2 | import binutil # required to import from dreamcoder modules 3 | except ModuleNotFoundError: 4 | import bin.binutil # alt import if called as module 5 | 6 | from dreamcoder.domains.text.main import (LearnedFeatureExtractor, main, 7 | text_options) 8 | from dreamcoder.dreamcoder import commandlineArguments 9 | from dreamcoder.utilities import numberOfCPUs 10 | 11 | if __name__ == "__main__": 12 | arguments = commandlineArguments( 13 | recognitionTimeout=7200, 14 | iterations=10, 15 | helmholtzRatio=0.5, 16 | topK=2, 17 | maximumFrontier=5, 18 | structurePenalty=10.0, 19 | a=3, 20 | activation="tanh", 21 | CPUs=numberOfCPUs(), 22 | featureExtractor=LearnedFeatureExtractor, 23 | pseudoCounts=30.0, 24 | extras=text_options, 25 | enumerationTimeout=300 # todo: how long? 26 | ) 27 | main(arguments) 28 | -------------------------------------------------------------------------------- /dreamcoder/bin/tower.py: -------------------------------------------------------------------------------- 1 | try: 2 | import binutil # required to import from dreamcoder modules 3 | except ModuleNotFoundError: 4 | import bin.binutil # alt import if called as module 5 | 6 | from dreamcoder.domains.tower.main import TowerCNN, main, tower_options 7 | from dreamcoder.dreamcoder import commandlineArguments 8 | from dreamcoder.utilities import numberOfCPUs 9 | 10 | if __name__ == "__main__": 11 | arguments = commandlineArguments( 12 | featureExtractor=TowerCNN, 13 | CPUs=numberOfCPUs(), 14 | helmholtzRatio=0.5, 15 | recognitionTimeout=3600, 16 | iterations=6, 17 | a=3, 18 | structurePenalty=1, 19 | pseudoCounts=10, 20 | topK=2, 21 | maximumFrontier=5, 22 | extras=tower_options, 23 | ) 24 | main(arguments) 25 | -------------------------------------------------------------------------------- /dreamcoder/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.6' 2 | services: 3 | pix2code: 4 | privileged: true 5 | container_name: pix2code 6 | image: pix2code-image 7 | build: 8 | context: . 9 | dockerfile: Dockerfile 10 | volumes: 11 | - /path-to-repo/pix2code/dreamcoder:/workspace/ 12 | entrypoint: bash 13 | stdin_open: true 14 | tty: true 15 | deploy: 16 | resources: 17 | reservations: 18 | devices: 19 | - driver: nvidia 20 | device_ids: [ '6' ] 21 | capabilities: [ gpu ] 22 | -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/deprecated/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/dreamcoder/deprecated/__init__.py -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/domains/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/dreamcoder/domains/__init__.py -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/domains/arithmetic/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/dreamcoder/domains/arithmetic/__init__.py -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/domains/arithmetic/arithmeticPrimitives.py: -------------------------------------------------------------------------------- 1 | from dreamcoder.program import * 2 | from dreamcoder.type import * 3 | 4 | 5 | def _addition(x): 6 | return lambda y: x + y 7 | 8 | 9 | def _subtraction(x): 10 | return lambda y: x - y 11 | 12 | 13 | def _division(x): 14 | return lambda y: x / y 15 | 16 | 17 | subtraction = Primitive("-", arrow(tint, arrow(tint, tint)), _subtraction) 18 | real_subtraction = Primitive("-.", arrow(treal, treal, treal), _subtraction) 19 | addition = Primitive("+", arrow(tint, arrow(tint, tint)), Curried(_addition)) 20 | real_addition = Primitive("+.", arrow(treal, treal, treal), _addition) 21 | 22 | 23 | def _multiplication(x): 24 | return lambda y: x * y 25 | 26 | 27 | multiplication = Primitive("*", arrow(tint, arrow(tint, tint)), _multiplication) 28 | real_multiplication = Primitive("*.", arrow(treal, treal, treal), _multiplication) 29 | real_division = Primitive("/.", arrow(treal, treal, treal), _division) 30 | 31 | 32 | def _power(a): 33 | return lambda b: a**b 34 | 35 | 36 | real_power = Primitive("power", arrow(treal, treal, treal), _power) 37 | 38 | k1 = Primitive("1", tint, 1) 39 | k_negative1 = Primitive("negative_1", tint, -1) 40 | k0 = Primitive("0", tint, 0) 41 | for n in range(2, 10): 42 | Primitive(str(n), tint, n) 43 | 44 | f1 = Primitive("1.", treal, 1.0) 45 | f0 = Primitive("0.", treal, 0) 46 | real = Primitive("REAL", treal, None) 47 | fpi = Primitive("pi", treal, 3.14) 48 | -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/domains/list/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/dreamcoder/domains/list/__init__.py -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/domains/logo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/dreamcoder/domains/logo/__init__.py -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/domains/misc/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/dreamcoder/domains/misc/__init__.py -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/domains/regex/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/dreamcoder/domains/regex/__init__.py -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/domains/text/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/dreamcoder/domains/text/__init__.py -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/domains/tower/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/dreamcoder/domains/tower/__init__.py -------------------------------------------------------------------------------- /dreamcoder/dreamcoder/ec.py: -------------------------------------------------------------------------------- 1 | print( 2 | "DEPRECATION NOTICE: this module (dreamcoder.ec) will be deleted soon, " 3 | "please update your code to import from dreamcoder.dreamcoder instead" 4 | ) 5 | from dreamcoder.dreamcoder import * # noqa 6 | -------------------------------------------------------------------------------- /dreamcoder/evaluation_script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SPLIT=$1 4 | SEED=$2 5 | 6 | # Set the path to the folder you want to monitor 7 | TARGET_FOLDER="consoleOutputs/clevr_single_support/$SPLIT/eval" 8 | 9 | # Set the target number of files 10 | TARGET_FILE_COUNT=$(ls -1 "$TARGET_FOLDER" | wc -l) 11 | 12 | # Index for eval 13 | IDX=$3 14 | 15 | echo $SPLIT $SEED $IDX 16 | 17 | # Function to run a file inside the container 18 | run_file() { 19 | docker exec -it pix2code sh $1 $2 $3 $4 20 | } 21 | 22 | # Build the Docker image 23 | docker stop pix2code 24 | docker rm pix2code 25 | docker compose build 26 | docker compose up -d 27 | 28 | while [ "$IDX" -le 125 ]; do 29 | echo start loop with $IDX 30 | 31 | # Run the initial file 32 | run_file run_eval.sh $IDX $SPLIT $SEED 33 | IDX=$((IDX+1)) 34 | 35 | docker stop pix2code 36 | docker rm pix2code 37 | docker compose build 38 | docker compose up -d 39 | 40 | done 41 | -------------------------------------------------------------------------------- /dreamcoder/evaluation_script_all_cube.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SPLIT="all_cubes" 4 | SEED=$1 5 | 6 | # Set the path to the folder you want to monitor 7 | TARGET_FOLDER="consoleOutputs/all_cubes/eval" 8 | 9 | # Set the target number of files 10 | TARGET_FILE_COUNT=$(ls -1 "$TARGET_FOLDER" | wc -l) 11 | 12 | # Index for eval 13 | IDX=0 14 | 15 | echo $SPLIT $SEED $IDX 16 | 17 | # Function to run a file inside the container 18 | run_file() { 19 | sh $1 $2 $3 $4 20 | } 21 | 22 | while [ "$IDX" -le 1 ]; do 23 | echo start loop with $IDX 24 | 25 | # Run the initial file 26 | run_file run_eval.sh $IDX $SPLIT $SEED 27 | IDX=$((IDX+1)) 28 | 29 | done 30 | -------------------------------------------------------------------------------- /dreamcoder/evaluation_script_all_metal_one_gray.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SPLIT="all_metal_one_gray" 4 | SEED=$1 5 | 6 | # Set the path to the folder you want to monitor 7 | TARGET_FOLDER="consoleOutputs/clevr/all_metal_one_gray/eval" 8 | 9 | # Set the target number of files 10 | TARGET_FILE_COUNT=$(ls -1 "$TARGET_FOLDER" | wc -l) 11 | 12 | # Index for eval 13 | IDX=0 14 | 15 | echo $SPLIT $SEED $IDX 16 | 17 | # Function to run a file inside the container 18 | run_file() { 19 | sh $1 $2 $3 $4 20 | } 21 | 22 | while [ "$IDX" -le 0 ]; do 23 | echo start loop with $IDX 24 | 25 | # Run the initial file 26 | run_file run_eval.sh $IDX $SPLIT $SEED 27 | IDX=$((IDX+1)) 28 | 29 | done 30 | -------------------------------------------------------------------------------- /dreamcoder/evaluation_script_revised_color_count.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SPLIT="color_count" 4 | SEED=0 5 | 6 | # Set the path to the folder you want to monitor 7 | TARGET_FOLDER="consoleOutputs/clevr_revised/$SPLIT/eval" 8 | 9 | # Set the target number of files 10 | TARGET_FILE_COUNT=$(ls -1 "$TARGET_FOLDER" | wc -l) 11 | 12 | # Index for eval 13 | IDX=0 14 | 15 | echo $SPLIT $SEED $IDX 16 | 17 | # Function to run a file inside the container 18 | run_file() { 19 | docker exec -it pix2code sh $1 $2 $3 $4 20 | } 21 | 22 | # Build the Docker image 23 | docker stop pix2code 24 | docker rm pix2code 25 | docker compose build 26 | docker compose up -d 27 | 28 | while [ "$IDX" -le 125 ]; do 29 | echo start loop with $IDX 30 | 31 | # Run the initial file 32 | run_file run_eval_revised.sh $IDX $SPLIT $SEED 33 | IDX=$((IDX+1)) 34 | 35 | docker stop pix2code 36 | docker rm pix2code 37 | docker compose build 38 | docker compose up -d 39 | 40 | done 41 | -------------------------------------------------------------------------------- /dreamcoder/failures/.dummy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/failures/.dummy -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.swp 3 | *.egg-info/ 4 | results/ 5 | data/*/data 6 | dist 7 | build 8 | *.zip -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/ocaml_client.ml: -------------------------------------------------------------------------------- 1 | open Unix 2 | 3 | (* 4 | * TODO : string are not as good as bytes 5 | *) 6 | 7 | let str = "behaviour/404_squareOfCircle" 8 | 9 | let gen_test () = 10 | let data = Bigarray.(Array1.create int8_unsigned c_layout (28 * 28)) in 11 | Bigarray.Array1.fill data 128 ; 12 | let bytes_version = Bytes.create (28 * 28) in 13 | for i = 0 to (28 * 28) - 1 do 14 | Bytes.set bytes_version i (char_of_int (data.{i})) 15 | done ; 16 | Bytes.to_string bytes_version 17 | 18 | 19 | 20 | let _ = 21 | let s_in, s_out = open_connection (ADDR_UNIX("./protonet_socket")) in 22 | let str2 = gen_test () in 23 | output_binary_int s_out (String.length str) ; 24 | output_string s_out str ; 25 | output_binary_int s_out (String.length str2) ; 26 | output_string s_out str2 ; 27 | flush s_out ; 28 | let l = input_binary_int s_in in 29 | let dist = really_input_string s_in l in 30 | prerr_endline dist ; 31 | output_binary_int s_out (String.length str) ; 32 | output_string s_out str ; 33 | output_binary_int s_out (String.length str2) ; 34 | output_string s_out str2 ; 35 | flush s_out ; 36 | let l = input_binary_int s_in in 37 | let dist = really_input_string s_in l in 38 | prerr_endline dist ; 39 | output_binary_int s_out (String.length "DONE") ; 40 | output_string s_out "DONE" ; 41 | flush s_out ; 42 | shutdown_connection s_in ; 43 | close_in s_in 44 | 45 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/protonets/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/prototypical-networks/protonets/__init__.py -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/protonets/models/__init__.py: -------------------------------------------------------------------------------- 1 | import protonets.models.few_shot 2 | from protonets.models.factory import get_model, register_model 3 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/protonets/models/factory.py: -------------------------------------------------------------------------------- 1 | MODEL_REGISTRY = {} 2 | 3 | 4 | def register_model(model_name): 5 | def decorator(f): 6 | MODEL_REGISTRY[model_name] = f 7 | return f 8 | 9 | return decorator 10 | 11 | 12 | def get_model(model_name, model_opt): 13 | if model_name in MODEL_REGISTRY: 14 | return MODEL_REGISTRY[model_name](**model_opt) 15 | else: 16 | raise ValueError("Unknown model {:s}".format(model_name)) 17 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/protonets/models/utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | 4 | def euclidean_dist(x, y): 5 | # x: N x D 6 | # y: M x D 7 | n = x.size(0) 8 | m = y.size(0) 9 | d = x.size(1) 10 | assert d == y.size(1) 11 | 12 | x = x.unsqueeze(1).expand(n, m, d) 13 | y = y.unsqueeze(0).expand(n, m, d) 14 | 15 | return torch.pow(x - y, 2).sum(2) 16 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/protonets/utils/__init__.py: -------------------------------------------------------------------------------- 1 | def filter_opt(opt, tag): 2 | ret = {} 3 | 4 | for k, v in opt.items(): 5 | tokens = k.split(".") 6 | if tokens[0] == tag: 7 | ret[".".join(tokens[1:])] = v 8 | 9 | return ret 10 | 11 | 12 | def format_opts(d): 13 | ret = [] 14 | for k, v in d.items(): 15 | if isinstance(v, bool) and v == True: 16 | ret = ret + ["--" + k] 17 | elif isinstance(v, bool) and v == False: 18 | pass 19 | else: 20 | ret = ret + ["--" + k, str(v)] 21 | return ret 22 | 23 | 24 | def merge_dict(x, y): 25 | ret = x.copy() 26 | 27 | for k, v in y.items(): 28 | ret[k] = v 29 | 30 | return ret 31 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/protonets/utils/data.py: -------------------------------------------------------------------------------- 1 | import protonets.data.geometry 2 | 3 | 4 | def load(opt, splits): 5 | # if opt['data.dataset'] == 'omniglot': 6 | # ds = protonets.data.omniglot.load(opt, splits) 7 | if opt["data.dataset"] == "geometry": 8 | ds = protonets.data.geometry.load(opt, splits) 9 | else: 10 | raise ValueError("Unknown dataset: {:s}".format(opt["data.dataset"])) 11 | 12 | return ds 13 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/protonets/utils/log.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | import numpy as np 4 | 5 | 6 | def extract_meter_values(meters): 7 | ret = {} 8 | 9 | for split in meters.keys(): 10 | ret[split] = {} 11 | for field, meter in meters[split].items(): 12 | ret[split][field] = meter.value()[0] 13 | 14 | return ret 15 | 16 | 17 | def render_meter_values(meter_values): 18 | field_info = [] 19 | for split in meter_values.keys(): 20 | for field, val in meter_values[split].items(): 21 | field_info.append("{:s} {:s} = {:0.6f}".format(split, field, val)) 22 | 23 | return ", ".join(field_info) 24 | 25 | 26 | def convert_array(d): 27 | ret = {} 28 | for k, v in d.items(): 29 | if isinstance(v, dict): 30 | ret[k] = {} 31 | for kk, vv in v.items(): 32 | ret[k][kk] = np.array(vv) 33 | else: 34 | ret[k] = np.array(v) 35 | 36 | return ret 37 | 38 | 39 | def load_trace(trace_file): 40 | ret = {} 41 | 42 | with open(trace_file, "r") as f: 43 | for i, line in enumerate(f): 44 | vals = json.loads(line.rstrip("\n")) 45 | 46 | if i == 0: 47 | for k, v in vals.items(): 48 | if isinstance(v, dict): 49 | ret[k] = {} 50 | for kk in v.keys(): 51 | ret[k][kk] = [] 52 | else: 53 | ret[k] = [] 54 | 55 | for k, v in vals.items(): 56 | if isinstance(v, dict): 57 | for kk, vv in v.items(): 58 | ret[k][kk].append(vv) 59 | else: 60 | ret[k].append(v) 61 | 62 | return convert_array(ret) 63 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/protonets/utils/model.py: -------------------------------------------------------------------------------- 1 | from protonets.models import get_model 2 | from protonets.utils import filter_opt 3 | from tqdm import tqdm 4 | 5 | 6 | def load(opt): 7 | model_opt = filter_opt(opt, "model") 8 | model_name = model_opt["model_name"] 9 | 10 | del model_opt["model_name"] 11 | 12 | return get_model(model_name, model_opt) 13 | 14 | 15 | def evaluate(model, data_loader, meters, desc=None): 16 | model.eval() 17 | 18 | for field, meter in meters.items(): 19 | meter.reset() 20 | 21 | if desc is not None: 22 | data_loader = tqdm(data_loader, desc=desc) 23 | 24 | for sample in data_loader: 25 | _, output = model.loss(sample) 26 | for field, meter in meters.items(): 27 | meter.add(output[field]) 28 | 29 | return meters 30 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/results-OM/best_model.pt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/prototypical-networks/results-OM/best_model.pt -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/results-OM/opt.json: -------------------------------------------------------------------------------- 1 | {"data.dataset": "geometry", "data.split": "sable-meyer", "data.way": 100, "data.shot": 5, "data.query": 5, "data.test_way": 5, "data.test_shot": 0, "data.test_query": 15, "data.train_episodes": 100, "data.test_episodes": 100, "data.trainval": false, "data.sequential": false, "data.cuda": true, "model.model_name": "protonet_conv", "model.x_dim": "1,28,28", "model.hid_dim": 64, "model.z_dim": 64, "train.epochs": 10000, "train.optim_method": "Adam", "train.learning_rate": 0.001, "train.decay_every": 20, "train.weight_decay": 0.0, "train.patience": 200, "log.fields": "loss,acc", "log.exp_dir": "results"} 2 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/scripts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/prototypical-networks/scripts/__init__.py -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/scripts/predict/few_shot/run_eval.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | from eval import main 4 | 5 | parser = argparse.ArgumentParser(description="Evaluate few-shot prototypical networks") 6 | 7 | default_model_path = "results/best_model.pt" 8 | parser.add_argument( 9 | "--model.model_path", 10 | type=str, 11 | default=default_model_path, 12 | metavar="MODELPATH", 13 | help="location of pretrained model to evaluate (default: {:s})".format( 14 | default_model_path 15 | ), 16 | ) 17 | 18 | parser.add_argument( 19 | "--data.test_way", 20 | type=int, 21 | default=0, 22 | metavar="TESTWAY", 23 | help="number of classes per episode in test. 0 means same as model's data.test_way (default: 0)", 24 | ) 25 | parser.add_argument( 26 | "--data.test_shot", 27 | type=int, 28 | default=0, 29 | metavar="TESTSHOT", 30 | help="number of support examples per class in test. 0 means same as model's data.shot (default: 0)", 31 | ) 32 | parser.add_argument( 33 | "--data.test_query", 34 | type=int, 35 | default=0, 36 | metavar="TESTQUERY", 37 | help="number of query examples per class in test. 0 means same as model's data.query (default: 0)", 38 | ) 39 | parser.add_argument( 40 | "--data.test_episodes", 41 | type=int, 42 | default=1000, 43 | metavar="NTEST", 44 | help="number of test episodes per epoch (default: 1000)", 45 | ) 46 | 47 | args = vars(parser.parse_args()) 48 | 49 | main(args) 50 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/scripts/train/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/prototypical-networks/scripts/train/__init__.py -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/scripts/train/few_shot/run_trainval.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | from trainval import main 4 | 5 | parser = argparse.ArgumentParser( 6 | description="Re-run prototypical networks training in trainval mode" 7 | ) 8 | 9 | parser.add_argument( 10 | "--model.model_path", 11 | type=str, 12 | default="results/best_model.pt", 13 | metavar="MODELPATH", 14 | help="location of pretrained model to retrain in trainval mode", 15 | ) 16 | 17 | args = vars(parser.parse_args()) 18 | 19 | main(args) 20 | -------------------------------------------------------------------------------- /dreamcoder/prototypical-networks/scripts/train/few_shot/trainval.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import subprocess 4 | 5 | from protonets.utils import format_opts, merge_dict 6 | from protonets.utils.log import load_trace 7 | 8 | 9 | def main(opt): 10 | result_dir = os.path.dirname(opt["model.model_path"]) 11 | 12 | # get target training loss to exceed 13 | trace_file = os.path.join(result_dir, "trace.txt") 14 | trace_vals = load_trace(trace_file) 15 | best_epoch = trace_vals["val"]["loss"].argmin() 16 | 17 | # load opts 18 | model_opt_file = os.path.join(os.path.dirname(opt["model.model_path"]), "opt.json") 19 | with open(model_opt_file, "r") as f: 20 | model_opt = json.load(f) 21 | 22 | # override previous training ops 23 | model_opt = merge_dict( 24 | model_opt, 25 | { 26 | "log.exp_dir": os.path.join(model_opt["log.exp_dir"], "trainval"), 27 | "data.trainval": True, 28 | "train.epochs": best_epoch + model_opt["train.patience"], 29 | }, 30 | ) 31 | 32 | subprocess.call( 33 | ["python", os.path.join(os.getcwd(), "scripts/train/few_shot/run_train.py")] 34 | + format_opts(model_opt) 35 | ) 36 | -------------------------------------------------------------------------------- /dreamcoder/requirements.txt: -------------------------------------------------------------------------------- 1 | Box2D-kengz 2 | cairocffi 3 | certifi 4 | cffi 5 | chardet 6 | colorama 7 | cycler 8 | dill 9 | frozendict 10 | graphviz 11 | idna 12 | joblib 13 | kiwisolver 14 | matplotlib 15 | multiprocess 16 | nltk 17 | numpy 18 | pathos 19 | Pillow 20 | pox 21 | ppft 22 | protobuf 23 | psutil 24 | pycparser 25 | pygame 26 | pyparsing 27 | pypng 28 | python-dateutil 29 | pytz 30 | pyzmq 31 | requests 32 | scikit-learn 33 | scipy 34 | sexpdata 35 | six 36 | torch 37 | torchvision 38 | urllib3 39 | 40 | # own 41 | rtpt 42 | -------------------------------------------------------------------------------- /dreamcoder/run_eval.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----------------------------------------------------------# 4 | N_TASKS=100 5 | CPUS=96 6 | TASK_FOLDER=$2 7 | EVAL=1 8 | DATE=`date +%Y-%m-%d-%H-%M` 9 | SEED=$3 10 | DOMAIN="clevr" 11 | #----------------------------------------------------------# 12 | 13 | c=$1 14 | echo "Start evaluation ${c} for ${TASK_FOLDER} with time stamp ${DATE}" 15 | python -u bin/clevr.py --task_folder $TASK_FOLDER --number_tasks $N_TASKS -c $CPUS --seed $SEED --eval $EVAL --test_idx $c> consoleOutputs/$DOMAIN/$TASK_FOLDER/eval/$SEED/${DATE}_eval_${c}.out 2> consoleOutputs/$DOMAIN/$TASK_FOLDER/eval/$SEED/${DATE}_eval_${c}.err 16 | -------------------------------------------------------------------------------- /dreamcoder/run_eval_kand.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----------------------------------------------------------# 4 | N_TASKS=100 5 | CPUS=96 6 | TASK_FOLDER="kandinsky" 7 | EVAL=1 8 | DATE=`date +%Y-%m-%d-%H-%M` 9 | SEED=$1 10 | DOMAIN="kandinsky" 11 | #----------------------------------------------------------# 12 | 13 | c=0 14 | echo "Start evaluation ${c} for ${TASK_FOLDER} with time stamp ${DATE}" 15 | python -u bin/relations.py --task_folder $TASK_FOLDER --number_tasks $N_TASKS -c $CPUS --seed $SEED --eval $EVAL --test_idx $c> consoleOutputs/$DOMAIN/eval/$SEED/${DATE}_eval_${c}.out 2> consoleOutputs/$DOMAIN/eval/$SEED/${DATE}_eval_${c}.err 16 | -------------------------------------------------------------------------------- /dreamcoder/run_eval_revised.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----------------------------------------------------------# 4 | N_TASKS=100 5 | CPUS=96 6 | TASK_FOLDER=$1 7 | EVAL=1 8 | DATE=`date +%Y-%m-%d-%H-%M` 9 | SEED=$2 10 | DOMAIN="clevr_revised" 11 | #----------------------------------------------------------# 12 | 13 | c=0 14 | echo "Start evaluation ${c} for ${TASK_FOLDER} with time stamp ${DATE}" 15 | python -u bin/clevr_revise_color_count.py --task_folder $TASK_FOLDER --number_tasks $N_TASKS -c $CPUS --seed $SEED --eval $EVAL --test_idx $c> consoleOutputs/$DOMAIN/$TASK_FOLDER/eval/$SEED/${DATE}_eval_${c}.out 2> consoleOutputs/$DOMAIN/$TASK_FOLDER/eval/$SEED/${DATE}_eval_${c}.err 16 | -------------------------------------------------------------------------------- /dreamcoder/run_experiment.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----------------------------------------------------------# 4 | N_TASKS=100 5 | CPUS=96 6 | TASK_FOLDER=$1 7 | EVAL=0 8 | DATE=`date +%Y-%m-%d-%H-%M` 9 | COMPRESSOR="ocaml" 10 | SEED=$2 11 | #----------------------------------------------------------# 12 | 13 | echo "Start experiment for ${TASK_FOLDER} with time stamp ${DATE}" 14 | python -u bin/clevr.py --task_folder $TASK_FOLDER --number_tasks $N_TASKS -c $CPUS --compressor $COMPRESSOR --seed $SEED --eval $EVAL> consoleOutputs/clevr/$TASK_FOLDER/${DATE}_clevr_${N_TASKS}.out 2> consoleOutputs/clevr/$TASK_FOLDER/${DATE}_clevr_${N_TASKS}.err 15 | -------------------------------------------------------------------------------- /dreamcoder/run_experiment_color_count.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----------------------------------------------------------# 4 | N_TASKS=100 5 | CPUS=96 6 | TASK_FOLDER="color_count" 7 | EVAL=0 8 | DATE=`date +%Y-%m-%d-%H-%M` 9 | COMPRESSOR="ocaml" 10 | SEED=0 11 | #----------------------------------------------------------# 12 | 13 | echo "Start experiment for ${TASK_FOLDER} with time stamp ${DATE}" 14 | python -u bin/clevr_revise_color_count.py --task_folder $TASK_FOLDER --number_tasks $N_TASKS -c $CPUS --compressor $COMPRESSOR --seed $SEED --eval $EVAL> consoleOutputs/clevr_revised/$TASK_FOLDER/train/$SEED/${DATE}_clevr_${N_TASKS}.out 2> consoleOutputs/clevr_revised/$TASK_FOLDER/train/$SEED/${DATE}_clevr_${N_TASKS}.err 15 | -------------------------------------------------------------------------------- /dreamcoder/run_experiment_confounded.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----------------------------------------------------------# 4 | N_TASKS=8 5 | CPUS=16 6 | TASK_FOLDER="confounded" 7 | EVAL=0 8 | DATE=`date +%Y-%m-%d-%H-%M` 9 | COMPRESSOR="ocaml" 10 | SEED=0 11 | #----------------------------------------------------------# 12 | 13 | echo "Start experiment for ${TASK_FOLDER} with time stamp ${DATE}" 14 | python -u bin/clevr_revised.py --task_folder $TASK_FOLDER --number_tasks $N_TASKS -c $CPUS --compressor $COMPRESSOR --seed $SEED --eval $EVAL> consoleOutputs/clevr_revised/$TASK_FOLDER/train/$SEED/${DATE}_clevr_${N_TASKS}.out 2> consoleOutputs/clevr_revised/$TASK_FOLDER/train/$SEED/${DATE}_clevr_${N_TASKS}.err 15 | -------------------------------------------------------------------------------- /dreamcoder/run_kandinsky.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #----------------------------------------------------------# 4 | N_TASKS=100 5 | CPUS=96 6 | TASK_FOLDER="kandinsky" 7 | EVAL=false 8 | DATE=`date +%Y-%m-%d-%H-%M` 9 | COMPRESSOR="ocaml" 10 | SEED=$1 11 | #----------------------------------------------------------# 12 | 13 | echo "Start experiment for ${TASK_FOLDER} with time stamp ${DATE}" 14 | python -u bin/relations.py --task_folder $TASK_FOLDER --number_tasks $N_TASKS -c $CPUS --compressor $COMPRESSOR --seed $SEED> consoleOutputs/$TASK_FOLDER/${DATE}_kandinsky_${N_TASKS}_${COMPRESSOR}${EVAL_STR}.out 2> consoleOutputs/$TASK_FOLDER/${DATE}_kandinsky_${N_TASKS}_${COMPRESSOR}${EVAL_STR}.err -------------------------------------------------------------------------------- /dreamcoder/runtests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Ensure tests are run from project root 4 | cd "$( dirname "${BASH_SOURCE[0]}" )" 5 | 6 | # Run dreamcoder unit tests 7 | python -m unittest discover tests 8 | -------------------------------------------------------------------------------- /dreamcoder/rust_compressor/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rust_compressor" 3 | version = "0.2.0" 4 | 5 | [dependencies] 6 | chashmap = "2.2" 7 | clap = "2.32" 8 | itertools = "0.7" 9 | polytype = "6.0" 10 | programinduction = { version = "0.7.4" , features = [ "verbose" ] } 11 | rayon = "1.0" 12 | serde = "1.0" 13 | serde_json = "1.0" 14 | serde_derive = "1.0" 15 | -------------------------------------------------------------------------------- /dreamcoder/rust_compressor/Makefile: -------------------------------------------------------------------------------- 1 | default: rust_compressor 2 | 3 | rust_compressor: Cargo.toml Cargo.lock src/*.rs 4 | cargo build --release 5 | mv target/release/rust_compressor ./ 6 | strip rust_compressor 7 | -------------------------------------------------------------------------------- /dreamcoder/rust_compressor/rust_compressor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/rust_compressor/rust_compressor -------------------------------------------------------------------------------- /dreamcoder/solvers/EC.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | open Utils 4 | open Type 5 | open Program 6 | open Enumeration 7 | open Task 8 | open Grammar 9 | open Compression 10 | open Sfg 11 | 12 | 13 | let rec exploration_compression 14 | (tasks : task list) 15 | (g : grammar) 16 | (frontier_size : int) 17 | ?keepTheBest:(keepTheBest = 1) 18 | ?arity:(arity = 0) 19 | (* lambda: penalty on the size of the structure of the grammar *) 20 | ?lambda:(lambda = 2.) 21 | (* alpha: pseudo counts for parameter estimation of grammar *) 22 | ?alpha:(alpha = 1.) 23 | (* beta: coefficient of AIC penalty *) 24 | ?beta:(beta = 1.) 25 | (iterations : int) 26 | : grammar = 27 | if iterations = 0 then g else 28 | let frontiers = enumerate_solutions_for_tasks g tasks frontier_size ~keepTheBest:keepTheBest in 29 | 30 | Printf.printf "Hit %d/%d of the tasks with a frontier of size %d.\n" 31 | (frontiers |> List.filter ~f:(fun f -> List.length f.programs > 0) |> List.length) 32 | (List.length frontiers) 33 | frontier_size; 34 | 35 | Out_channel.flush stdout; 36 | 37 | (* estimate_categorized_fragment_grammar (fragment_grammar_of_grammar g) frontiers; *) 38 | 39 | let fragments = time_it "Proposing fragments" @@ fun _ -> propose_fragments_from_frontiers arity frontiers in 40 | 41 | Printf.printf "Proposed %d fragments.\n" (List.length fragments); 42 | 43 | (* fragments |> List.iter ~f:(fun f -> Printf.printf "FRAGMENT\t%s\n" (string_of_fragment f)); *) 44 | 45 | Out_channel.flush stdout; 46 | 47 | let gf = time_it "Induced grammar" @@ fun _ -> 48 | induce_fragment_grammar ~lambda:lambda ~alpha:alpha ~beta:beta 49 | fragments frontiers (fragment_grammar_of_grammar g) in 50 | 51 | Out_channel.flush stdout; 52 | 53 | let gp = grammar_of_fragment_grammar gf in 54 | 55 | Printf.printf "GRAMMAR\n%s\n" (string_of_grammar gp); 56 | 57 | Out_channel.flush stdout; 58 | 59 | exploration_compression tasks gp frontier_size ~keepTheBest:keepTheBest (iterations - 1) 60 | 61 | -------------------------------------------------------------------------------- /dreamcoder/solvers/Euclid.ml: -------------------------------------------------------------------------------- 1 | type id = 2 | | C 3 | | P of id 4 | and point = 5 | | Intr of twoDType * twoDType 6 | | On of twoDType (* This is a random point *on* object X *) 7 | | Id1 of id 8 | | Any 9 | and twoDType = 10 | | Circ of point * point 11 | | Line of point * point 12 | | Id2 of id 13 | and element = 14 | | OneD of point 15 | | TwoD of twoDType 16 | and construction = End | Rest of element * construction (* (e,c) list *) 17 | 18 | let rec reconcat l = match l with 19 | | [] -> End 20 | | x::r -> Rest(x,(reconcat r)) 21 | 22 | let eqTriangle = 23 | reconcat 24 | [ OneD(Any) ; 25 | OneD(Any) ; 26 | TwoD(Circ(Id1(P(P(C))),Id1(P(C)))) ; 27 | TwoD(Circ(Id1(P(P(C))),Id1(P(P(P(C)))))) ; 28 | OneD(Intr(Id2(P(P(C))),Id2(P(C)))) ; 29 | TwoD(Line(Id1(P(P(P(P(P(C)))))),Id1(P(P(P(P(C))))))) ; 30 | TwoD(Line(Id1(P(P(P(P(P(P(C))))))),Id1(P(P(C))))) ; 31 | TwoD(Line(Id1(P(P(P(P(P(P(C))))))),Id1(P(P(P(C)))))) ] 32 | 33 | let _ = (* Do nothing. I'm interested in the typing so far. *) 34 | print_endline "Success, I was typed." 35 | -------------------------------------------------------------------------------- /dreamcoder/solvers/PolyValue.ml: -------------------------------------------------------------------------------- 1 | open Core 2 | 3 | open Utils 4 | open Type 5 | 6 | open Yojson.Basic 7 | 8 | module PolyValue = struct 9 | type t = 10 | | List of t list 11 | | Integer of int 12 | | Float of float 13 | | Boolean of bool 14 | | Character of char 15 | | None 16 | [@@deriving compare, hash, sexp_of] 17 | 18 | let rec pack t v : t = 19 | match t with 20 | | TCon("list",[t'],_) -> List(magical v |> List.map ~f:(pack t')) 21 | | TCon("int",[],_) -> Integer(magical v) 22 | | TCon("bool",[],_) -> Boolean(magical v) 23 | | TCon("char",[],_) -> Character(magical v) 24 | | _ -> assert false 25 | 26 | let is_some = function 27 | | None -> false 28 | | _ -> true 29 | 30 | let rec to_string = function 31 | | List(l) -> l |> List.map ~f:to_string |> join ~separator:";" |> Printf.sprintf "[%s]" 32 | | Integer(l) -> Printf.sprintf "%d" l 33 | | Float(f) -> Printf.sprintf "%f" f 34 | | Boolean(b) -> Printf.sprintf "%b" b 35 | | Character(c) -> Printf.sprintf "'%c'" c 36 | | None -> "None" 37 | 38 | let rec of_json (j : Yojson.Basic.json) : t = match j with 39 | | `List(l) -> List(l |> List.map ~f:of_json) 40 | | `Int(i) -> Integer(i) 41 | | `Bool(b) -> Boolean(b) 42 | | _ -> assert (false) 43 | 44 | end;; 45 | 46 | let make_poly_table() = Hashtbl.create (module PolyValue) 47 | 48 | 49 | module PolyList = struct 50 | type t = PolyValue.t list 51 | [@@deriving compare, hash, sexp_of] 52 | end;; 53 | 54 | let make_poly_list_table() = Hashtbl.create (module PolyList) 55 | -------------------------------------------------------------------------------- /dreamcoder/solvers/cache_pb.mli: -------------------------------------------------------------------------------- 1 | (** cache.proto Binary Encoding *) 2 | 3 | 4 | (** {2 Protobuf Encoding} *) 5 | 6 | val encode_tower_cash_block : Cache_types.tower_cash_block -> Pbrt.Encoder.t -> unit 7 | (** [encode_tower_cash_block v encoder] encodes [v] with the given [encoder] *) 8 | 9 | val encode_tower_cash_entry : Cache_types.tower_cash_entry -> Pbrt.Encoder.t -> unit 10 | (** [encode_tower_cash_entry v encoder] encodes [v] with the given [encoder] *) 11 | 12 | val encode_tower_cash : Cache_types.tower_cash -> Pbrt.Encoder.t -> unit 13 | (** [encode_tower_cash v encoder] encodes [v] with the given [encoder] *) 14 | 15 | 16 | (** {2 Protobuf Decoding} *) 17 | 18 | val decode_tower_cash_block : Pbrt.Decoder.t -> Cache_types.tower_cash_block 19 | (** [decode_tower_cash_block decoder] decodes a [tower_cash_block] value from [decoder] *) 20 | 21 | val decode_tower_cash_entry : Pbrt.Decoder.t -> Cache_types.tower_cash_entry 22 | (** [decode_tower_cash_entry decoder] decodes a [tower_cash_entry] value from [decoder] *) 23 | 24 | val decode_tower_cash : Pbrt.Decoder.t -> Cache_types.tower_cash 25 | (** [decode_tower_cash decoder] decodes a [tower_cash] value from [decoder] *) 26 | -------------------------------------------------------------------------------- /dreamcoder/solvers/cache_types.ml: -------------------------------------------------------------------------------- 1 | [@@@ocaml.warning "-27-30-39"] 2 | 3 | 4 | type tower_cash_block = { 5 | x10 : int32; 6 | w10 : int32; 7 | h10 : int32; 8 | } 9 | 10 | type tower_cash_entry = { 11 | plan : tower_cash_block list; 12 | height : float; 13 | stability : float; 14 | area : float; 15 | length : float; 16 | overpass : float; 17 | staircase : float; 18 | } 19 | 20 | type tower_cash = { 21 | entries : tower_cash_entry list; 22 | } [@@unboxed] 23 | 24 | let rec default_tower_cash_block 25 | ?x10:((x10:int32) = 0l) 26 | ?w10:((w10:int32) = 0l) 27 | ?h10:((h10:int32) = 0l) 28 | () : tower_cash_block = { 29 | x10; 30 | w10; 31 | h10; 32 | } 33 | 34 | let rec default_tower_cash_entry 35 | ?plan:((plan:tower_cash_block list) = []) 36 | ?height:((height:float) = 0.) 37 | ?stability:((stability:float) = 0.) 38 | ?area:((area:float) = 0.) 39 | ?length:((length:float) = 0.) 40 | ?overpass:((overpass:float) = 0.) 41 | ?staircase:((staircase:float) = 0.) 42 | () : tower_cash_entry = { 43 | plan; 44 | height; 45 | stability; 46 | area; 47 | length; 48 | overpass; 49 | staircase; 50 | } 51 | 52 | let rec default_tower_cash 53 | ?entries:((entries:tower_cash_entry list) = []) 54 | () : tower_cash = { 55 | entries; 56 | } 57 | -------------------------------------------------------------------------------- /dreamcoder/solvers/cache_types.mli: -------------------------------------------------------------------------------- 1 | (** cache.proto Types *) 2 | 3 | 4 | 5 | (** {2 Types} *) 6 | 7 | type tower_cash_block = { 8 | x10 : int32; 9 | w10 : int32; 10 | h10 : int32; 11 | } 12 | 13 | type tower_cash_entry = { 14 | plan : tower_cash_block list; 15 | height : float; 16 | stability : float; 17 | area : float; 18 | length : float; 19 | overpass : float; 20 | staircase : float; 21 | } 22 | 23 | type tower_cash = { 24 | entries : tower_cash_entry list; 25 | } [@@unboxed] 26 | 27 | 28 | (** {2 Default values} *) 29 | 30 | val default_tower_cash_block : 31 | ?x10:int32 -> 32 | ?w10:int32 -> 33 | ?h10:int32 -> 34 | unit -> 35 | tower_cash_block 36 | (** [default_tower_cash_block ()] is the default value for type [tower_cash_block] *) 37 | 38 | val default_tower_cash_entry : 39 | ?plan:tower_cash_block list -> 40 | ?height:float -> 41 | ?stability:float -> 42 | ?area:float -> 43 | ?length:float -> 44 | ?overpass:float -> 45 | ?staircase:float -> 46 | unit -> 47 | tower_cash_entry 48 | (** [default_tower_cash_entry ()] is the default value for type [tower_cash_entry] *) 49 | 50 | val default_tower_cash : 51 | ?entries:tower_cash_entry list -> 52 | unit -> 53 | tower_cash 54 | (** [default_tower_cash ()] is the default value for type [tower_cash] *) 55 | -------------------------------------------------------------------------------- /dreamcoder/solvers/client.ml: -------------------------------------------------------------------------------- 1 | open Core 2 | 3 | open Zmq 4 | 5 | type socket_connection = (([`Req] Zmq.Socket.t) ref * int) ;; 6 | let context = ref (Zmq.Context.create());; 7 | let socket_connections : (socket_connection list) ref = ref [];; 8 | 9 | let socket_json (socket : socket_connection) message = 10 | let open Yojson.Safe in 11 | let message = to_string message in 12 | let socket,_ = socket in 13 | Zmq.Socket.send !socket message; 14 | let response = Zmq.Socket.recv !socket in 15 | response |> from_string 16 | 17 | let connect_socket' p : [`Req] Zmq.Socket.t = 18 | let socket = Zmq.Socket.create !context Zmq.Socket.req in 19 | Zmq.Socket.connect socket @@ "tcp://localhost:"^(p |> Int.to_string); 20 | socket 21 | 22 | let connect_socket p : socket_connection = 23 | let s = connect_socket' p in 24 | let s = (ref s,p) in 25 | socket_connections := s :: !socket_connections; 26 | s 27 | 28 | let refresh_socket_connections() = 29 | match !socket_connections with 30 | [] -> () 31 | | _ -> begin 32 | context := Zmq.Context.create(); 33 | socket_connections := !socket_connections |> List.map ~f:(fun (r,p) -> 34 | r := connect_socket' p; 35 | (r,p)); 36 | end 37 | 38 | let close_socket_connections() = 39 | !socket_connections |> List.iter ~f:(fun (r,p) -> 40 | Zmq.Socket.close !r); 41 | socket_connections := [] 42 | 43 | (* let rec test socket = *) 44 | (* Zmq.Socket.send socket message; *) 45 | (* let response = Zmq.Socket.recv socket in *) 46 | (* assert (response = message); *) 47 | (* Printf.printf "Client received %s\n" response; *) 48 | (* Pervasives.flush stdout; *) 49 | (* test socket;; *) 50 | (* let () = *) 51 | (* let socket = Zmq.Socket.create context Zmq.Socket.req in *) 52 | (* Zmq.Socket.connect socket "tcp://localhost:9119"; *) 53 | (* test socket *) 54 | (* ;; *) 55 | -------------------------------------------------------------------------------- /dreamcoder/solvers/color.ml: -------------------------------------------------------------------------------- 1 | 2 | (* h: [0,1] *) 3 | (* s: [0,1] *) 4 | (* l: [0,1] *) 5 | 6 | let hsl2rgb h s l = 7 | if s = 0. then (1.,1.,1.) else 8 | let h2rgb p q t = 9 | let t = 10 | if t < 0. then t+.1. else t 11 | in 12 | let t = 13 | if t > 1. then t-.1. else t 14 | in 15 | if t < 1./.6. then p+.(q-.p)*.6.*.t else 16 | if t < 1./.2. then q else 17 | if t < 2./.3. then p+.(q-.p)*.(2./.3.-.t)*.6. else 18 | p 19 | in 20 | 21 | let q = 22 | if l < 0.5 then l*.(1.+.s) else l+.s-.l*.s 23 | in 24 | let p = 2.*.l -. q in 25 | (h2rgb p q (h+.1./.3.), 26 | h2rgb p q h, 27 | h2rgb p q (h-.1./.3.)) 28 | 29 | let rgb2hsl r g b = 30 | let maximum = max r (max b g) in 31 | let minimum = min r (min b g) in 32 | 33 | if maximum = minimum then (0., 0., maximum) else 34 | 35 | let d = maximum-.minimum in 36 | let l = (maximum+.minimum)/.2. in 37 | let s = if l > 0.5 then d/.(2.-.maximum-.minimum) else d/.(maximum+.minimum) 38 | in 39 | 40 | let h = 41 | if maximum = r then (g-.b)/.d +. (if g < b then 6. else 0.) else 42 | if maximum = g then (b-.r)/.d +. 2. else 43 | if maximum = b then (r-.g)/.d +. 4. else 44 | assert false 45 | in 46 | let h = h/.6. in 47 | (h,s,l) 48 | 49 | let interpolate_color (r1,g1,b1) (r2,g2,b2) = 50 | let (h1,s1,l1) = rgb2hsl r1 g1 b1 in 51 | let (h2,s2,l2) = rgb2hsl r2 g2 b2 in 52 | fun distance -> 53 | let h = h1 +. (h2-.h1)*.distance in 54 | let s = s1 +. (s2-.s1)*.distance in 55 | let l = l1 +. (l2-.l1)*.distance in 56 | hsl2rgb h s l 57 | -------------------------------------------------------------------------------- /dreamcoder/solvers/funarray.mli: -------------------------------------------------------------------------------- 1 | (* 2 | funarray.mli 3 | 4 | Port of Chris Okasaki's purely functional 5 | random-access list to CAML: supports random access 6 | and pure functional updates AND supports head/tail 7 | operations in O(1) 8 | 9 | Construct a random-access list with 10 | cons elt empty 11 | -> returns elt::empty 12 | 13 | Access an element of a random-access list with 14 | lookup ls idx 15 | -> returns element at idx 16 | 17 | Update an element of a random-access list with 18 | update ls idx new 19 | -> returns new list with new replacing former element at idx 20 | 21 | --- 22 | 23 | ported by Will Benton, 10/5/2004 24 | 25 | distributed under the GNU GPL 26 | *) 27 | 28 | type 'a funarray (* functional array type *) 29 | 30 | exception Subscript 31 | exception Empty 32 | 33 | val empty : 'a funarray 34 | val lookup : 'a funarray -> int -> 'a 35 | val update : 'a funarray -> int -> 'a -> 'a funarray 36 | val isempty : 'a funarray -> bool 37 | val cons : 'a -> 'a funarray -> 'a funarray 38 | val head : 'a funarray -> 'a 39 | val tail : 'a funarray -> 'a funarray 40 | val from_list : 'a list -> 'a funarray 41 | -------------------------------------------------------------------------------- /dreamcoder/solvers/geomGenerate.ml: -------------------------------------------------------------------------------- 1 | open Plotter 2 | open Renderer 3 | open Interpreter 4 | open Printf 5 | open Images 6 | open Generator 7 | 8 | let _ = Random.self_init () 9 | 10 | 11 | let gen_name () = 12 | string_of_int (Random.int 1048576) (* This is 2 ** 20 *) 13 | 14 | let base = "./generated" 15 | 16 | let save ?image:(image=false) p c name cost = 17 | let s = pp_shapeprogram p in 18 | let oc = 19 | open_out 20 | (Printf.sprintf "%s/%s.LoG" base name) in 21 | let oc_w = 22 | open_out 23 | (Printf.sprintf "%s/%s.cost" base name) in 24 | Printf.fprintf oc "%s" s ; 25 | Printf.fprintf oc_w "%d\n" cost ; 26 | close_out oc ; 27 | close_out oc_w ; 28 | if image then begin 29 | let fname = Printf.sprintf "%s/%s.png" base name in 30 | output_canvas_png c 16 fname ; 31 | let fname = Printf.sprintf "%s/%s_HIGH.png" base name in 32 | output_canvas_png c 64 fname 33 | end 34 | 35 | let () = 36 | let sup = 5000 in 37 | let generated = Hashtbl.create (sup / 10) in 38 | let i = ref 0 in 39 | while !i < sup do 40 | let p = generate_random () in 41 | let cost = costProgram p in 42 | try begin 43 | let c = interpret p in 44 | let l = Plumbing.canvas_to_tlist c in 45 | try begin 46 | let c',name = Hashtbl.find generated l in 47 | if c' < cost then () 48 | else begin 49 | Hashtbl.replace generated l (cost,name) ; 50 | save p c name cost 51 | end 52 | end with Not_found -> 53 | begin 54 | let name = gen_name () in 55 | Hashtbl.add generated l (cost,name) ; 56 | i := !i + 1 ; 57 | save ~image:(true) p c name cost 58 | end 59 | end with MalformedProgram(s) -> () 60 | done 61 | 62 | -------------------------------------------------------------------------------- /dreamcoder/solvers/geomLib/Plotter.ml: -------------------------------------------------------------------------------- 1 | open Vg 2 | open Gg 3 | 4 | type canvas = P.t * Gg.Box2.t 5 | 6 | let d_from_origin = 1. 7 | 8 | let new_canvas () = (P.sub (Gg.P2.v d_from_origin d_from_origin) P.empty, 9 | Gg.Box2.empty) 10 | 11 | let middle_x = fun _ -> d_from_origin 12 | let middle_y = fun _ -> d_from_origin 13 | 14 | let moveto : canvas -> float -> float -> canvas = 15 | fun (path, box) x y -> 16 | let new_path = P.sub (P2.v x y) path in 17 | (new_path, box) 18 | 19 | let lineto : canvas -> float -> float -> canvas = 20 | fun (path, box) x y -> 21 | let new_path = P.line (P2.v x y) path in 22 | (new_path, Gg.Box2.add_pt box (Gg.P2.v x y)) 23 | 24 | let print_canvas canvas = 25 | let (canvas,_) = canvas in 26 | print_endline (P.to_string canvas) 27 | -------------------------------------------------------------------------------- /dreamcoder/solvers/geomLib/Plumbing.ml: -------------------------------------------------------------------------------- 1 | open Interpreter 2 | open Renderer 3 | 4 | let bigarrayWith0s size = 5 | let data = Bigarray.(Array1.create int8_unsigned c_layout size) in 6 | Bigarray.Array1.fill data 0 ; 7 | data 8 | 9 | let canvas_to_tlist size canvas = 10 | try begin 11 | canvas_to_1Darray canvas size 12 | end 13 | with Invalid_argument _ -> 14 | bigarrayWith0s size 15 | 16 | let relist data = (* SLOWWWWW *) 17 | let l = ref [] in 18 | for i = (Bigarray.Array1.dim data) - 1 downto 0 do 19 | l := data.{i}::(!l) 20 | done ; 21 | !l 22 | 23 | let nop = Nop 24 | let concat p1 p2 = Concat(p1,p2) 25 | let embed p = Embed(p) 26 | let turn x = Turn(x) 27 | let define x = Define("MyOnlyVar",x) 28 | let repeat v p = Repeat(v,p) 29 | let run ?size:(size=28) p = canvas_to_tlist size (interpret p) 30 | 31 | let integrate v1 v2 v3 v4 = Integrate(v1,Some(v2),(None,v3,v4,None)) 32 | let basic_line = Integrate(None,Some(true),(None,None,None,None)) 33 | 34 | let var_unit = Unit 35 | let var_two = Next(Unit) 36 | let var_three = Next(Next(Unit)) 37 | let var_half v = Half(v) 38 | let var_double v = Double(v) 39 | let var_next v = Next(v) 40 | let var_prev v = Prev(v) 41 | let var_divide v v'= Divide(v,v') 42 | let var_opposite v = Opposite(v) 43 | let var_name = Name("MyOnlyVar") 44 | -------------------------------------------------------------------------------- /dreamcoder/solvers/geomLib/Renderer.ml: -------------------------------------------------------------------------------- 1 | open Vg 2 | open Gg 3 | open Plotter 4 | open Cairo 5 | 6 | type canvas = Plotter.canvas 7 | 8 | let output_canvas_png : ?smart:bool -> 9 | canvas -> int -> string -> unit = 10 | fun ?smart:(smart=false) (canvas, box) desired fname -> 11 | let (view,size,image) = Utils2.get_infos smart d_from_origin box canvas in 12 | let res = (float_of_int desired) /. (Gg.Size2.h size) in 13 | let rel = 1000. *. res in (* Sorry, for some reason the unit changes here 14 | from mm to m...! *) 15 | let fmt = `Png (Size2.v rel rel) in 16 | let warn w = Vgr.pp_warning Format.err_formatter w in 17 | let oc = open_out fname in 18 | let r = Vgr.create ~warn (Vgr_cairo.stored_target fmt) (`Channel oc) in 19 | ignore (Vgr.render r (`Image (size, view, image))) ; 20 | ignore (Vgr.render r `End) ; 21 | close_out oc 22 | 23 | let canvas_to_1Darray = 24 | fun ?smart:(smart=false) (canvas, box) desired -> 25 | let (view,size,image) = Utils2.get_infos smart d_from_origin box canvas in 26 | let res = (float_of_int desired) /. (Gg.Size2.h size) in 27 | let w,h = desired,desired in 28 | let stride = Cairo.Image.(stride_for_width A8 w) in 29 | let data = Bigarray.(Array1.create int8_unsigned c_layout (stride * h)) in 30 | let surface = Cairo.Image.(create_for_data8 data A8 ~stride ~w ~h) in 31 | let ctx = Cairo.create surface in 32 | Cairo.scale ctx res res; 33 | let target = Vgr_cairo.target ctx in 34 | let warn w = Vgr.pp_warning Format.err_formatter w in 35 | let r = Vgr.create ~warn target `Other in 36 | ignore (Vgr.render r (`Image (size, view, image))) ; 37 | ignore (Vgr.render r `End) ; 38 | Cairo.Surface.flush surface ; 39 | Cairo.Surface.finish surface ; 40 | data 41 | -------------------------------------------------------------------------------- /dreamcoder/solvers/geomLib/jbuild: -------------------------------------------------------------------------------- 1 | (jbuild_version 1) 2 | 3 | (ocamllex (lambdaLexer)) 4 | (ocamllex (geomLexer)) 5 | 6 | (menhir 7 | ((modules (lambdaParser)))) 8 | 9 | (menhir 10 | ((modules (geomParser)))) 11 | 12 | (library 13 | ((name geomLib) 14 | (libraries (vg vg.cairo)))) 15 | -------------------------------------------------------------------------------- /dreamcoder/solvers/geomLib/lambdaLexer.mll: -------------------------------------------------------------------------------- 1 | { 2 | open Lexing 3 | open LambdaParser 4 | exception SyntaxError of string 5 | } 6 | 7 | let white = [' ' '\t' '\n' '\r']+ 8 | 9 | rule read = 10 | parse 11 | | white { read lexbuf } 12 | | '#' { read lexbuf } (* Completely ignore this symbol [1] *) 13 | | '(' { LP } 14 | | ')' { RP } 15 | | "run" { RUN } 16 | | "embed" { EMBED } 17 | | "turn" { TURN } 18 | | "repeat" { REPEAT } 19 | | "nothing" { NOTHING } 20 | | "define" { DEFINE } 21 | | "just" { JUST } 22 | | "integrate" { INTEGRATE } 23 | | "concat" { CONCAT } 24 | | "basic_line" { LINE } 25 | | "var_unit" { V_U } 26 | | "var_two" { V_2 } 27 | | "var_three" { V_3 } 28 | | "var_name" { NAME } 29 | | "var_next" { V_N } 30 | | "var_prev" { V_P } 31 | | "var_half" { V_H } 32 | | "var_double" { V_D } 33 | | "var_divide" { V_Di } 34 | | "var_opposite" { V_O } 35 | | "true" { TRUE } 36 | | "false" { FALSE } 37 | | eof { EOF } 38 | 39 | (* 40 | * [1]: It means "EC invented this as a "new" instuction of cost 1" but the new 41 | * instruction is under this symbol so at execute time we just ingore this. 42 | *) 43 | -------------------------------------------------------------------------------- /dreamcoder/solvers/geomTest.ml: -------------------------------------------------------------------------------- 1 | open GeomLib 2 | open Plotter 3 | open Renderer 4 | open Interpreter 5 | open Printf 6 | 7 | (*let prog = (Plumbing.concat Plumbing.integrate*) 8 | (*(Plumbing.concat (Plumbing.turn None) Plumbing.integrate))*) 9 | (*let prog2 = Plumbing.repeat (Plumbing.repeat prog)*) 10 | let empty = Turn(None) 11 | let line = Integrate(None,None,(None,None,None,None)) 12 | let angle = Concat(line,Concat(Turn(None),line)) 13 | let square = Repeat(None,Repeat(None,Concat(line,Turn(None)))) 14 | let circle = Integrate(None,None,(None,None, Some(Unit),None)) 15 | let dashes = Repeat(None,Repeat(None,Concat(line, 16 | Integrate(None,Some(false),(None,None,None,None))))) 17 | let spiral = Integrate(None,None,(None,None,None,Some(Unit))) 18 | (*let spiral = Integrate(None,None,(None,Some(Unit),Some(Unit), None))*) 19 | 20 | 21 | let pp l data = 22 | for i = 0 to (Bigarray.Array1.dim data) - 1 do 23 | if (i mod l) == 0 then print_newline () ; 24 | print_int (data.{i}) 25 | done 26 | 27 | let npp data = 28 | for i = 0 to (Bigarray.Array1.dim data) - 1 do 29 | print_int (data.{i}) 30 | done 31 | 32 | let () = 33 | let choice = spiral in 34 | let (path,box) = interpret choice in 35 | let l = Plumbing.run choice in 36 | print_canvas (path,box) ; 37 | pp 32 l ; 38 | npp l ; 39 | print_newline () ; 40 | output_canvas_png (path,box) 512 "toto.png" 41 | 42 | -------------------------------------------------------------------------------- /dreamcoder/solvers/heap_search.ml: -------------------------------------------------------------------------------- 1 | open Core 2 | 3 | -------------------------------------------------------------------------------- /dreamcoder/solvers/jbuild: -------------------------------------------------------------------------------- 1 | (jbuild_version 1) 2 | 3 | (executables 4 | ((names (solver compression helmholtz geomDrawLambdaString geomDrawFile geomTest logoTest logoDrawString logoSequenceString protonet-tester client versionDemo)) 5 | (modes (native)) 6 | (ocamlopt_flags (:standard -O3 -unboxed-types -nodynlink -w -20)) 7 | (libraries (core re2 yojson geomLib logoLib ocaml-protoc zmq)) ;parmap 8 | (preprocess (pps (ppx_jane))) 9 | )) 10 | -------------------------------------------------------------------------------- /dreamcoder/solvers/logoLib/Colors.ml: -------------------------------------------------------------------------------- 1 | (* h: [0,1] *) 2 | (* s: [0,1] *) 3 | (* l: [0,1] *) 4 | 5 | let hsl2rgb h s l = 6 | if s = 0. then (1.,1.,1.) else 7 | let h2rgb p q t = 8 | let t = 9 | if t < 0. then t+.1. else t 10 | in 11 | let t = 12 | if t > 1. then t-.1. else t 13 | in 14 | if t < 1./.6. then p+.(q-.p)*.6.*.t else 15 | if t < 1./.2. then q else 16 | if t < 2./.3. then p+.(q-.p)*.(2./.3.-.t)*.6. else 17 | p 18 | in 19 | 20 | let q = 21 | if l < 0.5 then l*.(1.+.s) else l+.s-.l*.s 22 | in 23 | let p = 2.*.l -. q in 24 | (h2rgb p q (h+.1./.3.), 25 | h2rgb p q h, 26 | h2rgb p q (h-.1./.3.)) 27 | 28 | let rgb2hsl r g b = 29 | let maximum = max r (max b g) in 30 | let minimum = min r (min b g) in 31 | 32 | if maximum = minimum then (0., 0., maximum) else 33 | 34 | let d = maximum-.minimum in 35 | let l = (maximum+.minimum)/.2. in 36 | let s = if l > 0.5 then d/.(2.-.maximum-.minimum) else d/.(maximum+.minimum) 37 | in 38 | 39 | let h = 40 | if maximum = r then (g-.b)/.d +. (if g < b then 6. else 0.) else 41 | if maximum = g then (b-.r)/.d +. 2. else 42 | if maximum = b then (r-.g)/.d +. 4. else 43 | assert false 44 | in 45 | let h = h/.6. in 46 | (h,s,l) 47 | 48 | let interpolate_color (r1,g1,b1) (r2,g2,b2) = 49 | let (h1,s1,l1) = rgb2hsl r1 g1 b1 in 50 | let (h2,s2,l2) = rgb2hsl r2 g2 b2 in 51 | fun distance -> 52 | let h = h1 +. (h2-.h1)*.distance in 53 | let s = s1 +. (s2-.s1)*.distance in 54 | let l = l1 +. (l2-.l1)*.distance in 55 | hsl2rgb h s l 56 | 57 | -------------------------------------------------------------------------------- /dreamcoder/solvers/logoLib/jbuild: -------------------------------------------------------------------------------- 1 | (jbuild_version 1) 2 | 3 | (library 4 | ((name logoLib) 5 | (libraries (vg vg.cairo)))) 6 | -------------------------------------------------------------------------------- /dreamcoder/solvers/logoSequenceString.ml: -------------------------------------------------------------------------------- 1 | open LogoLib 2 | open LogoInterpreter 3 | open VGWrapper 4 | 5 | open Differentiation 6 | open Program 7 | 8 | let npp data = 9 | for i = 0 to (Bigarray.Array1.dim data) - 2 do 10 | print_int (data.{i}) ; print_char ',' ; 11 | done ; 12 | print_int (data.{((Bigarray.Array1.dim data) - 1)}) ; 13 | print_newline () 14 | 15 | let _ = 16 | let str = Sys.argv.(1) 17 | and folder = Sys.argv.(2) in 18 | try 19 | match parse_program str with 20 | | Some(p) -> 21 | prerr_endline "Parsed" ; 22 | let p = analyze_lazy_evaluation p in 23 | prerr_endline "Parsed" ; 24 | let turtle = run_lazy_analyzed_with_arguments p [] in 25 | let c = eval_turtle ~sequence:(folder^"/output_") turtle in 26 | prerr_endline "evaled" ; 27 | output_canvas_png c 512 (folder^".png") ; 28 | prerr_endline "drawn" 29 | | _ -> () 30 | with Invalid_argument _ | Failure _ | Stack_overflow -> () 31 | -------------------------------------------------------------------------------- /dreamcoder/solvers/parser.ml: -------------------------------------------------------------------------------- 1 | open Core 2 | 3 | type 'a parsing = (string*int -> ('a*int) list) 4 | 5 | let return_parse (x : 'a) : 'a parsing = 6 | fun (s,n) -> [(x,n)] 7 | 8 | let parse_failure : 'a parsing = 9 | fun (s,n) -> [] 10 | 11 | let bind_parse (x : 'a parsing) (f : 'a -> 'b parsing) : 'b parsing = 12 | fun (s,n) -> 13 | x (s,n) |> List.map ~f:(fun (xp,n') -> f xp (s,n')) |> List.concat 14 | 15 | let (%%) = bind_parse 16 | 17 | let (<|>) (x : 'a parsing) (y : 'a parsing) : 'a parsing = 18 | fun s -> 19 | x s @ y s 20 | 21 | let constant_parser (k : string) : unit parsing = 22 | fun (s,n) -> 23 | let rec check consumed = 24 | if consumed = String.length k then true else 25 | if n + consumed >= String.length s || s.[n + consumed] <> k.[consumed] then false else 26 | check (consumed + 1) 27 | in 28 | if check 0 then [(),n + String.length k] else [] 29 | 30 | let token_parser ?can_be_empty:(can_be_empty = false) (element : char -> bool) : string parsing = 31 | fun (s,n) -> 32 | let rec check consumed = 33 | if n + consumed >= String.length s || (not (element s.[n + consumed])) then [] else 34 | s.[n + consumed] :: check (consumed + 1) 35 | in 36 | let token = check 0 in 37 | if (not can_be_empty) && List.length token = 0 then [] else 38 | let token = String.concat ~sep:"" (token |> List.map ~f:(String.make 1)) in 39 | [(token, n + String.length token)] 40 | 41 | let run_parser (p : 'a parsing) (s : string) : 'a option = 42 | p (s,0) |> List.fold_right ~init:None ~f:(fun (r,n) a -> 43 | match a with 44 | | Some(_) -> a 45 | | None -> 46 | if String.length s = n then Some(r) else None) 47 | -------------------------------------------------------------------------------- /dreamcoder/solvers/polynomial.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | open Utils 4 | open Type 5 | open Program 6 | open Enumeration 7 | open Task 8 | open Grammar 9 | open Compression 10 | open EC 11 | 12 | let maximumCoefficient = 9 13 | 14 | let polynomial_tasks = 15 | (0--maximumCoefficient) |> List.map ~f:(fun a -> 16 | (0--maximumCoefficient) |> List.map ~f:(fun b -> 17 | (0--maximumCoefficient) |> List.map ~f:(fun c -> 18 | let examples = List.map (0--5) ~f:(fun x -> (x, a*x*x + b*x + c)) in 19 | let n = Printf.sprintf "(%i x^2 + %i x + %i)" a b c in 20 | supervised_task n (tint @> tint) examples))) 21 | |> List.concat |> List.concat 22 | 23 | let polynomial_grammar = 24 | primitive_grammar [ primitive0; 25 | primitive1; 26 | (* primitive2; *) 27 | (* primitive3; *) 28 | (* primitive4; *) 29 | (* primitive5; *) 30 | (* primitive6; *) 31 | (* primitive7; *) 32 | (* primitive8; *) 33 | (* primitive9; *) 34 | primitive_addition; 35 | primitive_multiplication; 36 | (* primitive_apply; *) 37 | ] 38 | 39 | 40 | 41 | let _ = 42 | exploration_compression polynomial_tasks polynomial_grammar ~keepTheBest:3 10000 1 ~alpha:10. 43 | -------------------------------------------------------------------------------- /dreamcoder/solvers/protonet-tester.ml: -------------------------------------------------------------------------------- 1 | open Unix 2 | 3 | open Program 4 | 5 | let _ = 6 | let idRef = Sys.argv.(1) 7 | and p = Sys.argv.(2) in 8 | let s_in, s_out = 9 | open_connection 10 | (ADDR_UNIX("./prototypical-networks/protonet_socket")) in 11 | let p = match parse_program p with | Some(p) -> p | _ -> failwith "NOP" in 12 | let p = analyze_lazy_evaluation p in 13 | let x = run_lazy_analyzed_with_arguments p [] in 14 | let l = LogoLib.LogoInterpreter.turtle_to_array x 28 in 15 | let bytes_version = Bytes.create (28 * 28) in 16 | for i = 0 to (28 * 28) - 1 do 17 | Bytes.set bytes_version i (char_of_int (l.{i})) 18 | done ; 19 | let img = Bytes.to_string bytes_version in 20 | output_binary_int s_out (String.length idRef) ; 21 | output_string s_out idRef ; 22 | output_binary_int s_out (String.length img) ; 23 | output_string s_out img ; 24 | flush s_out ; 25 | let l = input_binary_int s_in in 26 | let log_likelihood = (float_of_string (really_input_string s_in l)) in 27 | output_binary_int s_out (String.length "DONE") ; 28 | output_string s_out "DONE" ; 29 | flush s_out ; 30 | shutdown_connection s_in ; 31 | close_in s_in ; 32 | print_endline ( 33 | Printf.sprintf "Raw dist:\t%f\nProposal:\t%f" 34 | log_likelihood (-. (100. *. log_likelihood)) 35 | ) 36 | 37 | -------------------------------------------------------------------------------- /dreamcoder/solvers/recognition.ml: -------------------------------------------------------------------------------- 1 | open Core.Std 2 | 3 | open Task 4 | 5 | let export_task_features (tasks_and_targets : ((task*(float list)) list)) (testing : task list) (f : string) : unit = 6 | let open Yojson.Basic.Util in 7 | let serialize_vector v = 8 | `List(v |> List.map ~f:(fun f -> `Float(f))) 9 | in 10 | let features_of_task task = 11 | task.task_features |> serialize_vector 12 | in 13 | `Assoc( 14 | [("test", `List(testing |> List.map ~f:features_of_task)); 15 | ("train", `List(tasks_and_targets |> List.map ~f:(fun (task,output) -> 16 | `Assoc([("features", features_of_task task); 17 | ("target", serialize_vector output)]))))]) 18 | |> pretty_to_channel stdout 19 | -------------------------------------------------------------------------------- /dreamcoder/solvers/timeout.ml: -------------------------------------------------------------------------------- 1 | (* I hate Core *) 2 | 3 | open Unix 4 | 5 | exception Timeout 6 | 7 | let sigalrm_handler = Sys.Signal_handle (fun _ -> raise Timeout) 8 | 9 | let run_for_interval' (time : float) (c : unit -> 'a) : 'a option = 10 | (* Install a new alarm handler *) 11 | let old_behavior = Sys.signal Sys.sigalrm sigalrm_handler in 12 | let reset_sigalrm () = Sys.set_signal Sys.sigalrm old_behavior 13 | in 14 | try 15 | ignore (Unix.setitimer ITIMER_REAL {it_interval = 0.0; it_value = time}) ; 16 | let res = c () in 17 | ignore (Unix.setitimer ITIMER_REAL {it_interval = 0.0; it_value = 0.0}) ; 18 | reset_sigalrm () ; 19 | Some(res) 20 | with 21 | | Timeout -> 22 | begin 23 | ignore (Unix.setitimer ITIMER_REAL {it_interval = 0.0; it_value = 0.0}) ; 24 | reset_sigalrm () ; 25 | None 26 | end 27 | | e -> 28 | begin 29 | ignore (Unix.setitimer ITIMER_REAL {it_interval = 0.0; it_value = 0.0}) ; 30 | reset_sigalrm () ; 31 | raise e 32 | end 33 | 34 | 35 | (* This is stupid *) 36 | (* Turns out you can't really do millisecond timing and languages with garbage collection *) 37 | (* Because the fucking garbage collector could interrupt in the middle of the computation *) 38 | (* and ocaml, the wonderful language it is, does not allow you to temporarily disable the garbage collector *) 39 | (* So this version of run_for_interval allows you to repeatedly try to run the thing for the interval *) 40 | let rec run_for_interval ?attempts:(attempts=1) dt c = 41 | if attempts < 1 then None else 42 | match run_for_interval' dt c with 43 | | Some(v) -> Some(v) 44 | | None -> run_for_interval ~attempts:(attempts - 1) dt c 45 | -------------------------------------------------------------------------------- /dreamcoder/solvers/versionDemo.ml: -------------------------------------------------------------------------------- 1 | open Core 2 | open Versions 3 | open Program 4 | open Utils 5 | 6 | let _ = 7 | let t = new_version_table() in 8 | let p = "(#(lambda (lambda (* $2 (+ (lambda $2) $0)))) $0 2)" |> parse_program |> get_some in 9 | p |> incorporate t |> inline t |> extract t |> List.iter ~f:(fun p' -> 10 | Printf.printf "%s\n" 11 | (string_of_program p')); 12 | assert (false) 13 | ;; 14 | 15 | 16 | let _ = 17 | List.range 0 6 |> List.iter ~f:(fun sz -> 18 | let p0 = List.range 0 sz |> 19 | List.fold_right ~init:"(+ 1 1)" ~f:(fun _ -> Printf.sprintf "(+ 1 %s)") |> 20 | parse_program |> get_some 21 | in 22 | 23 | List.range 1 4 |> List.iter ~f:(fun a -> 24 | let v = new_version_table() in 25 | let j = incorporate v p0 in 26 | let r = List.range 0 a |> 27 | List.fold_right ~init:[j] ~f:(fun _ (a :: b) -> recursive_inversion v a :: a :: b) |> 28 | union v 29 | in 30 | 31 | let version_size : int = reachable_versions v [r] |> List.length in 32 | 33 | let ht = new_version_table() in 34 | let distinct_programs = extract v r |> List.map ~f:(incorporate ht) |> List.dedup_and_sort ~compare:(-) |> List.length in 35 | let program_memory = version_table_size ht in 36 | 37 | Printf.printf "version_size[%d,%d] = %d\n" 38 | sz a version_size; 39 | Printf.printf "distinct_programs[%d,%d] = %d\n" 40 | sz a distinct_programs; 41 | Printf.printf "program_memory[%d,%d] = %d\n" 42 | sz a program_memory; 43 | (* Printf.printf "approximate size = %f\n" *) 44 | (* (unique_space v r |> log_version_size v |> exp); *) 45 | flush_everything() 46 | )) 47 | 48 | 49 | -------------------------------------------------------------------------------- /dreamcoder/tests/README.md: -------------------------------------------------------------------------------- 1 | Tests 2 | ===== 3 | 4 | ### Unit tests 5 | 6 | To run unit tests from the root of the repo: 7 | ``` 8 | python -m unittest discover tests 9 | ``` 10 | 11 | Or, run the convenience script from the root of the repo: 12 | ``` 13 | ./tests/run 14 | ``` 15 | 16 | ### Integration tests 17 | 18 | 19 | While refactoring, run the following tests. 20 | 21 | Run the following 4 programs with small timeout to ensure no superficial bugs: 22 | 23 | 1. text.py 24 | ```bash 25 | singularity exec container.img python bin/text.py -t 2 -RS 5 -i 2 26 | ``` 27 | 2. list.py 28 | ```bash 29 | singularity exec container.img python bin/list.py -t 2 -RS 5 -i 2 30 | ``` 31 | 3. logo.py 32 | ```bash 33 | singularity exec container.img python bin/logo.py -t 5 -RS 10 --biasOptimal -i 2 34 | ``` 35 | 4. tower.py 36 | ```bash 37 | singularity exec container.img python bin/tower.py -t 2 -RS 5 -i 2 38 | ``` 39 | 40 | Single test command: 41 | ```bash 42 | singularity exec container.img python bin/text.py -t 2 -RS 5 -i 2 > text.out && singularity exec container.img python bin/list.py -t 2 -RS 5 -i 2 > list.out && singularity exec container.img python bin/logo.py -t 5 -RS 10 --biasOptimal -i 2 > logo.out 43 | ``` 44 | 45 | More extensive test command: 46 | ```bash 47 | singularity exec container.img python bin/tower.py -t 600 --pseudoCounts 30 \ 48 | --tasks new --aic 1.0 --structurePenalty 1.5 --topK 2 --arity 3 \ 49 | --maximumFrontier 5 -i 10 --storeTaskMetrics --split 0.5 \ 50 | --testingTimeout 600 --biasOptimal --contextual --primitives new --recognitionTimeout 3600 -RS 5000 51 | ``` 52 | 53 | Also run some graph.py tests from the root of the repo: 54 | ```bash 55 | bash tests/integration/runtests.sh 56 | ``` 57 | -------------------------------------------------------------------------------- /dreamcoder/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/tests/__init__.py -------------------------------------------------------------------------------- /dreamcoder/tests/integration/runtests.sh: -------------------------------------------------------------------------------- 1 | cd "$( dirname "${BASH_SOURCE[0]}" )" 2 | echo "$(pwd)" 3 | cd .. 4 | cd .. 5 | source venv/bin/activate || echo "activated" 6 | mkdir -p tests/out 7 | python bin/graphs.py --checkpoints tests/resources/kellis_list_exp.pickle --export tests/out/test.png 8 | -------------------------------------------------------------------------------- /dreamcoder/tests/resources/kellis_list_exp.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/dreamcoder/tests/resources/kellis_list_exp.pickle -------------------------------------------------------------------------------- /dreamcoder/tests/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # usage (from repo root): 4 | # 5 | # nohup bash ./tests/test.sh & echo $! > pidfile 6 | # 7 | 8 | singularity exec container.img python bin/text.py -t 2 -RS 5 -i 2 > text.out &&\ 9 | singularity exec container.img python bin/list.py -t 2 -RS 5 -i 2 > list.out && \ 10 | singularity exec container.img python bin/logo.py -t 5 -RS 10 --biasOptimal -i 2 > logo.out && \ 11 | singularity exec container.img python bin/regexes.py -i 1 -t 1 -RS 10 -R 10 \ 12 | --primitives reduced --tasks new --maxTasks 256 --ll_cutoff bigram --split 0.5 --pseudoCounts 30 \ 13 | -l -1000000 --aic -1000000 --structurePenalty 1.5 --topK 2 --arity 3 --primitives strConst \ 14 | --use_str_const -g > regexes.out && \ 15 | singularity exec container.img python bin/tower.py -t 2 -RS 5 -i 2 -l -1000000 --aic -1000000 \ 16 | --tasks new --primitives new -g > tower.out && \ 17 | singularity exec container.img python bin/scientificLaws.py -i 1 -t 1 -RS 10 -R 10 \ 18 | --pseudoCounts 30 -l -1000000 --aic -1000000 -g > scientificLaws.out && \ 19 | singularity exec container.img python bin/rational.py -i 1 -t 1 --testingTimeout 1 \ 20 | -RS 10 -R 10 --pseudoCounts 30 -l -1000000 --aic -1000000 -g > rational.out 21 | 22 | echo "exited with $?" > nohup.exitcode 23 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_compression.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestCompression(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.compression import induceGrammar, ocamlInduce 8 | except Exception: 9 | self.fail("Unable to import from compression module") 10 | 11 | 12 | if __name__ == "__main__": 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_dreamcoder.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestEcModule(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.dreamcoder import (ECResult, commandlineArguments, 8 | default_wake_generative, 9 | ecIterator, 10 | evaluateOnTestingTasks, 11 | sleep_recognition) 12 | except Exception: 13 | self.fail("Unable to import ec module") 14 | 15 | 16 | if __name__ == "__main__": 17 | unittest.main() 18 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_dreaming.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestDreaming(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.dreaming import (backgroundHelmholtzEnumeration, 8 | helmholtzEnumeration) 9 | except Exception: 10 | self.fail("Unable to import from dreaming module") 11 | 12 | 13 | if __name__ == "__main__": 14 | unittest.main() 15 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_fragmentGrammar.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestFragmentGrammar(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.fragmentGrammar import FragmentGrammar 8 | except Exception: 9 | self.fail("Unable to import from fragmentGrammar module") 10 | 11 | 12 | if __name__ == "__main__": 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_list.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestListMain(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.domains.list.main import (LearnedFeatureExtractor, 8 | isIntFunction, 9 | isListFunction, 10 | list_features, 11 | list_options, main, 12 | retrieveJSONTasks, 13 | train_necessary) 14 | except Exception: 15 | self.fail("Unable to import list module") 16 | 17 | 18 | if __name__ == "__main__": 19 | unittest.main() 20 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_logo.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestLogoMain(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.domains.logo.main import (Flatten, LogoFeatureCNN, 8 | animateSolutions, 9 | dreamFromGrammar, 10 | enumerateDreams, 11 | list_options, main, 12 | outputDreams, 13 | visualizePrimitives) 14 | except Exception: 15 | self.fail("Unable to import logo module") 16 | 17 | 18 | if __name__ == "__main__": 19 | unittest.main() 20 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_recognition.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestRecognition(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.recognition import RecognitionModel 8 | except Exception: 9 | self.fail("Unable to import from recognition module") 10 | 11 | 12 | if __name__ == "__main__": 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_regexes.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestRegexesMain(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.domains.regex.main import ( 8 | ConstantInstantiateVisitor, LearnedFeatureExtractor, 9 | MyJSONFeatureExtractor, main, regex_options) 10 | except Exception: 11 | self.fail("Unable to import regexes module") 12 | 13 | 14 | if __name__ == "__main__": 15 | unittest.main() 16 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_symmetryBreaking.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestSymmetryBreaking(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from bin.symmetryBreaking import main 8 | except Exception: 9 | self.fail("Unable to import from symmetryBreaking module") 10 | 11 | 12 | if __name__ == "__main__": 13 | unittest.main() 14 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_text.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestTextMain(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.domains.text.main import ( 8 | ConstantInstantiateVisitor, LearnedFeatureExtractor, 9 | competeOnOneTask, main, sygusCompetition, text_options) 10 | except Exception: 11 | self.fail("Unable to import text module") 12 | 13 | 14 | if __name__ == "__main__": 15 | unittest.main() 16 | -------------------------------------------------------------------------------- /dreamcoder/tests/test_tower.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | 4 | class TestTowerMain(unittest.TestCase): 5 | def test_imports(self): 6 | try: 7 | from dreamcoder.domains.tower.main import (Flatten, TowerCNN, 8 | dreamOfTowers, main, 9 | tower_options, 10 | visualizePrimitives) 11 | except Exception: 12 | self.fail("Unable to import tower module") 13 | 14 | 15 | if __name__ == "__main__": 16 | unittest.main() 17 | -------------------------------------------------------------------------------- /figures/all-cubes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/figures/all-cubes.jpg -------------------------------------------------------------------------------- /figures/all-metal-one-gray.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/figures/all-metal-one-gray.jpg -------------------------------------------------------------------------------- /figures/kandinsky.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/figures/kandinsky.jpg -------------------------------------------------------------------------------- /figures/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/figures/overview.png -------------------------------------------------------------------------------- /kandinsky/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/kandinsky/__init__.py -------------------------------------------------------------------------------- /kandinsky/generate.sh: -------------------------------------------------------------------------------- 1 | python generate_patterns.py twopairs & 2 | python generate_patterns.py threepairs & 3 | python generate_patterns.py closeby & 4 | python generate_patterns.py online-pair & 5 | python generate_patterns.py red-triangle & 6 | python generate_patterns.py closeby_pretrain & 7 | python generate_patterns.py online_pretrain & -------------------------------------------------------------------------------- /kandinsky/requirements.txt: -------------------------------------------------------------------------------- 1 | inflect>=2.1.0 2 | numpy>=1.16.2 3 | opencv-python>=4.1.0.25 4 | Pillow>=5.4.1 5 | -------------------------------------------------------------------------------- /kandinsky/src/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/kandinsky/src/__init__.py -------------------------------------------------------------------------------- /kandinsky/src/kp/KandinskyTruth.py: -------------------------------------------------------------------------------- 1 | import abc 2 | 3 | 4 | class KandinskyTruthInterfce: 5 | def __init__(self, universe, min=4, max=4): 6 | self.u = universe 7 | self.min = min 8 | self.max = max 9 | 10 | @abc.abstractmethod 11 | def humanDescription(self): 12 | return "" 13 | 14 | @abc.abstractmethod 15 | def isfuzzy(self): 16 | return False 17 | 18 | @abc.abstractmethod 19 | def true_kf(self, n=1): 20 | return [] 21 | 22 | @abc.abstractmethod 23 | def false_kf(self, n=1): 24 | return [] 25 | 26 | @abc.abstractmethod 27 | def almost_true_kf(self, n=1): 28 | return [] 29 | 30 | @abc.abstractmethod 31 | def kf(self, p, n=1): 32 | return [] 33 | -------------------------------------------------------------------------------- /kandinsky/src/kp/__init__.py: -------------------------------------------------------------------------------- 1 | print(f"Invoking __init__.py for {__name__}") 2 | -------------------------------------------------------------------------------- /kandinsky/src/map/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/kandinsky/src/map/__init__.py -------------------------------------------------------------------------------- /kandinsky/src/map/class_id_to_name.json: -------------------------------------------------------------------------------- 1 | { 2 | "0": "smallredtriangle", 3 | "1": "smallredsquare", 4 | "2": "smallredcircle", 5 | "3": "smallbluetriangle", 6 | "4": "smallbluesquare", 7 | "5": "smallbluecircle", 8 | "6": "smallyellowtriangle", 9 | "7": "smallyellowsquare", 10 | "8": "smallyellowcircle", 11 | "9": "mediumredtriangle", 12 | "10": "mediumredsquare", 13 | "11": "mediumredcircle", 14 | "12": "mediumbluetriangle", 15 | "13": "mediumbluesquare", 16 | "14": "mediumbluecircle", 17 | "15": "mediumyellowtriangle", 18 | "16": "mediumyellowsquare", 19 | "17": "mediumyellowcircle", 20 | "18": "bigredtriangle", 21 | "19": "bigredsquare", 22 | "20": "bigredcircle", 23 | "21": "bigbluetriangle", 24 | "22": "bigbluesquare", 25 | "23": "bigbluecircle", 26 | "24": "bigyellowtriangle", 27 | "25": "bigyellowsquare", 28 | "26": "bigyellowcircle" 29 | } -------------------------------------------------------------------------------- /kandinsky/src/map/class_name_to_id.json: -------------------------------------------------------------------------------- 1 | { 2 | "bigbluecircle": 23, 3 | "bigbluesquare": 22, 4 | "bigbluetriangle": 21, 5 | "bigredcircle": 20, 6 | "bigredsquare": 19, 7 | "bigredtriangle": 18, 8 | "bigyellowcircle": 26, 9 | "bigyellowsquare": 25, 10 | "bigyellowtriangle": 24, 11 | "mediumbluecircle": 14, 12 | "mediumbluesquare": 13, 13 | "mediumbluetriangle": 12, 14 | "mediumredcircle": 11, 15 | "mediumredsquare": 10, 16 | "mediumredtriangle": 9, 17 | "mediumyellowcircle": 17, 18 | "mediumyellowsquare": 16, 19 | "mediumyellowtriangle": 15, 20 | "smallbluecircle": 5, 21 | "smallbluesquare": 4, 22 | "smallbluetriangle": 3, 23 | "smallredcircle": 2, 24 | "smallredsquare": 1, 25 | "smallredtriangle": 0, 26 | "smallyellowcircle": 8, 27 | "smallyellowsquare": 7, 28 | "smallyellowtriangle": 6 29 | } -------------------------------------------------------------------------------- /kandinsky/src/map/concept_categories.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 0, 4 | "name": "small" 5 | }, 6 | { 7 | "id": 1, 8 | "name": "medium" 9 | }, 10 | { 11 | "id": 2, 12 | "name": "big" 13 | }, 14 | { 15 | "id": 3, 16 | "name": "red" 17 | }, 18 | { 19 | "id": 4, 20 | "name": "blue" 21 | }, 22 | { 23 | "id": 5, 24 | "name": "yellow" 25 | }, 26 | { 27 | "id": 6, 28 | "name": "triangle" 29 | }, 30 | { 31 | "id": 7, 32 | "name": "square" 33 | }, 34 | { 35 | "id": 8, 36 | "name": "circle" 37 | } 38 | ] -------------------------------------------------------------------------------- /kandinsky/src/map/concept_relation_categories.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 0, 4 | "name": "small" 5 | }, 6 | { 7 | "id": 1, 8 | "name": "medium" 9 | }, 10 | { 11 | "id": 2, 12 | "name": "big" 13 | }, 14 | { 15 | "id": 3, 16 | "name": "red" 17 | }, 18 | { 19 | "id": 4, 20 | "name": "blue" 21 | }, 22 | { 23 | "id": 5, 24 | "name": "yellow" 25 | }, 26 | { 27 | "id": 6, 28 | "name": "triangle" 29 | }, 30 | { 31 | "id": 7, 32 | "name": "square" 33 | }, 34 | { 35 | "id": 8, 36 | "name": "circle" 37 | }, 38 | { 39 | "id": 9, 40 | "name": "same_size" 41 | }, 42 | { 43 | "id": 10, 44 | "name": "same_color" 45 | }, 46 | { 47 | "id": 11, 48 | "name": "same_shape" 49 | } 50 | ] -------------------------------------------------------------------------------- /pix2seq/.gitignore: -------------------------------------------------------------------------------- 1 | # output dir 2 | results 3 | 4 | # compilation and distribution 5 | __pycache__ 6 | _ext 7 | *.pyc 8 | *.so 9 | build/ 10 | dist/ 11 | wheels/ 12 | 13 | # pytorch/python/numpy formats 14 | *.pth 15 | *.pkl 16 | *.npy 17 | 18 | # Pycharm editor settings 19 | .idea 20 | 21 | # dataset 22 | coco 23 | 24 | -------------------------------------------------------------------------------- /pix2seq/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nvcr.io/nvidia/pytorch:21.12-py3 2 | 3 | WORKDIR /workspace 4 | 5 | COPY requirements.txt . 6 | 7 | # Install python requirements 8 | RUN pip install -r requirements.txt 9 | -------------------------------------------------------------------------------- /pix2seq/README.md: -------------------------------------------------------------------------------- 1 | # Pretrained-Pix2Seq 2 | We provide the pre-trained model of Pix2Seq. This version contains new data augmentation. The model is trained for 300 epochs and can acheive 37 mAP without beam search or neucles search. 3 | 4 | 5 | ## Installation 6 | 7 | Install PyTorch 1.5+ and torchvision 0.6+ (recommend torch1.8.1 torchvision 0.8.0) 8 | 9 | Install pycocotools (for evaluation on COCO): 10 | 11 | ``` 12 | pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI' 13 | ``` 14 | 15 | That's it, should be good to train and evaluate detection models. 16 | 17 | ## Data preparation 18 | 19 | Download and extract COCO 2017 train and val images with annotations from 20 | [http://cocodataset.org](http://cocodataset.org/#download). 21 | We expect the directory structure to be the following: 22 | ``` 23 | path/to/coco/ 24 | annotations/ # annotation json files 25 | train2017/ # train images 26 | val2017/ # val images 27 | ``` 28 | 29 | ## Training 30 | 31 | First link coco dataset to the project folder 32 | ``` 33 | ln -s /path/to/coco ./coco 34 | ``` 35 | 36 | Training 37 | ``` 38 | sh train.sh --model pix2seq --output_dir /path/to/save 39 | ``` 40 | 41 | Evaluation 42 | ``` 43 | sh train.sh --model pix2seq --output_dir /path/to/save --resume /path/to/checkpoints --eval 44 | ``` 45 | 46 | ### COCO 47 | 48 | | Method | backbone | Epoch | Batch Size | AP | AP50 | AP75 | Weights | 49 | | :-----: | :------: | :----:| :---------:| :---:| :---: | :---: | :-----: | 50 | | Pix2Seq | R50 | 300 | 32 | 37.0 | 53.4 | 39.4 | [weight](https://drive.google.com/file/d/1b7KzqnEBIQCTKmk9SqsXNqX2nlTZSFV_/view?usp=sharing) | 51 | 52 | # Contributor 53 | Qiu Han, Peng Gao, Jingqiu Zhou(Beam Search) 54 | 55 | # Acknowledegement 56 | Pix2Seq, DETR 57 | -------------------------------------------------------------------------------- /pix2seq/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-research/pix2code/5717855f6730548b2cde3a636fe4a3c29d985e71/pix2seq/__init__.py -------------------------------------------------------------------------------- /pix2seq/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | import torch.utils.data 3 | import torchvision 4 | 5 | from .coco import build as build_coco 6 | from .clevr import build as build_clevr 7 | 8 | 9 | def get_coco_api_from_dataset(dataset): 10 | for _ in range(10): 11 | # if isinstance(dataset, torchvision.datasets.CocoDetection): 12 | # break 13 | if isinstance(dataset, torch.utils.data.Subset): 14 | dataset = dataset.dataset 15 | if isinstance(dataset, torchvision.datasets.CocoDetection): 16 | return dataset.coco 17 | 18 | 19 | def build_dataset(image_set, args): 20 | if args.dataset_file == 'coco': 21 | return build_coco(image_set, args) 22 | elif args.dataset_file == 'clevr': 23 | return build_clevr(image_set, args) 24 | raise ValueError(f'dataset {args.dataset_file} not supported') 25 | -------------------------------------------------------------------------------- /pix2seq/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | services: 3 | workspace: 4 | privileged: true 5 | container_name: pix2seq 6 | image: workspace-image 7 | build: 8 | context: . 9 | dockerfile: Dockerfile 10 | volumes: 11 | - //pix2code:/workspace 12 | entrypoint: bash 13 | stdin_open: true 14 | tty: true 15 | deploy: 16 | resources: 17 | reservations: 18 | devices: 19 | - driver: nvidia 20 | device_ids: [ "0", "1" ] 21 | capabilities: [ gpu ] 22 | -------------------------------------------------------------------------------- /pix2seq/playground/__init__.py: -------------------------------------------------------------------------------- 1 | from .pix2seq import build_pix2seq_model 2 | 3 | 4 | build_all_model = { 5 | "pix2seq": build_pix2seq_model, 6 | } 7 | -------------------------------------------------------------------------------- /pix2seq/playground/pix2seq/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | from .pix2seq import build 3 | 4 | 5 | def build_pix2seq_model(args): 6 | return build(args) 7 | -------------------------------------------------------------------------------- /pix2seq/playground/pix2seq/attention_layer.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn as nn 3 | 4 | 5 | class Attention(nn.Module): 6 | def __init__(self, dim, num_heads=8, dropout=0.): 7 | super().__init__() 8 | self.num_heads = num_heads 9 | head_dim = dim // num_heads 10 | self.scale = head_dim ** -0.5 11 | 12 | self.qkv = nn.Linear(dim, dim * 3) 13 | self.attn_drop = nn.Dropout(dropout) 14 | self.proj = nn.Linear(dim, dim) 15 | 16 | def forward(self, x, pre_kv=None, attn_mask=None): 17 | N, B, C = x.shape 18 | qkv = self.qkv(x).reshape(N, B, 3, self.num_heads, C // self.num_heads).permute(2, 1, 3, 0, 4) 19 | q, k, v = qkv[0], qkv[1], qkv[2] # make torchscript happy (cannot use tensor as tuple) 20 | 21 | if not self.training: 22 | k = torch.cat([pre_kv[0], k], dim=2) 23 | v = torch.cat([pre_kv[1], v], dim=2) 24 | pre_kv = torch.stack([k, v], dim=0) 25 | 26 | attn = (q @ k.transpose(-2, -1)) * self.scale 27 | 28 | if attn_mask is not None: 29 | attn.masked_fill_(attn_mask, float('-inf')) 30 | 31 | attn = attn.softmax(dim=-1) 32 | attn = self.attn_drop(attn) 33 | 34 | x = (attn @ v).permute(2, 0, 1, 3).reshape(N, B, C) 35 | x = self.proj(x) 36 | return x, pre_kv 37 | -------------------------------------------------------------------------------- /pix2seq/requirements.txt: -------------------------------------------------------------------------------- 1 | cython 2 | git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI&egg=pycocotools 3 | torch>=1.5.0 4 | torchvision>=0.6.0 5 | timm 6 | rtpt 7 | -------------------------------------------------------------------------------- /pix2seq/tox.ini: -------------------------------------------------------------------------------- 1 | [flake8] 2 | max-line-length = 120 3 | ignore = F401,E402,F403,W503,W504 4 | -------------------------------------------------------------------------------- /pix2seq/train.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | python -m torch.distributed.launch --nproc_per_node=2 --use_env main.py --pix2seq_lr --large_scale_jitter --rand_target $@ -------------------------------------------------------------------------------- /pix2seq/util/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved 2 | --------------------------------------------------------------------------------