From 49a5920066e3a52dbf541733e8f11b62f06a25b1 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Tue, 11 Jan 2022 12:52:15 -0500 Subject: [PATCH 01/28] Add BraTS integration with MLCube --- brats/.env | 13 + brats/.gitignore | 1 + brats/Dockerfile_CPU | 22 + brats/Dockerfile_CUDA | 27 + brats/LICENSE | 661 ++++++++++++++++++ brats/README.md | 35 + brats/mlcube_cpu.yaml | 22 + brats/mlcube_gpu.yaml | 22 + brats/requirements.txt | 1 + brats/run.py | 21 + brats/src/__init__.py | 0 brats/src/amazing_logic.py | 38 + brats/src/utils/__init__.py | 0 brats/src/utils/utilities.py | 4 + brats/workspace/data/results/.dockerignore | 1 + brats/workspace/data/results/.gitignore | 3 + brats/workspace/data/something_flair.nii.gz | 1 + .../data/something_survival_metadata.csv | 14 + brats/workspace/data/something_t1.nii.gz | 1 + brats/workspace/data/something_t1ce.nii.gz | 1 + brats/workspace/data/someting_t2.nii.gz | 1 + 21 files changed, 889 insertions(+) create mode 100644 brats/.env create mode 100644 brats/.gitignore create mode 100644 brats/Dockerfile_CPU create mode 100644 brats/Dockerfile_CUDA create mode 100644 brats/LICENSE create mode 100644 brats/README.md create mode 100644 brats/mlcube_cpu.yaml create mode 100644 brats/mlcube_gpu.yaml create mode 100644 brats/requirements.txt create mode 100644 brats/run.py create mode 100644 brats/src/__init__.py create mode 100644 brats/src/amazing_logic.py create mode 100644 brats/src/utils/__init__.py create mode 100644 brats/src/utils/utilities.py create mode 100644 brats/workspace/data/results/.dockerignore create mode 100644 brats/workspace/data/results/.gitignore create mode 100644 brats/workspace/data/something_flair.nii.gz create mode 100644 brats/workspace/data/something_survival_metadata.csv create mode 100644 brats/workspace/data/something_t1.nii.gz create mode 100644 brats/workspace/data/something_t1ce.nii.gz create mode 100644 brats/workspace/data/someting_t2.nii.gz diff --git a/brats/.env b/brats/.env new file mode 100644 index 0000000..6dc4217 --- /dev/null +++ b/brats/.env @@ -0,0 +1,13 @@ +# author info +AUTHOR_NAME = "Chuck Norris" +AUTHOR_EMAIL = "chuck@norris.org" +# put your app name here +APPLICATION_NAME = "AMAZING APPLICATION" +# specify version here, if possible use semantic versioning +APPLICATION_VERSION = "0.0.1" + +INPUT_FOLDER ="workspace/data/" +OUTPUT_FOLDER ="workspace/data/results/" + +INPUT_FOLDER_DOCKER="/app/data/" +OUTPUT_FOLDER_DOCKER ="/app/data/results/" \ No newline at end of file diff --git a/brats/.gitignore b/brats/.gitignore new file mode 100644 index 0000000..ba0430d --- /dev/null +++ b/brats/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/brats/Dockerfile_CPU b/brats/Dockerfile_CPU new file mode 100644 index 0000000..7a60a09 --- /dev/null +++ b/brats/Dockerfile_CPU @@ -0,0 +1,22 @@ +# for a CPU app use this Dockerfile, delete the Dockerfile_CUDA then. +FROM python:3.8-buster + +# fill in your info here +LABEL author="chuck@norris.org" +LABEL application="your application name" +LABEL maintainer="chuck@norris.org" +LABEL version="0.0.1" +LABEL status="beta" + +# basic +RUN apt-get -y update && apt -y full-upgrade && apt-get -y install apt-utils wget git tar build-essential curl nano + +# install all python requirements +WORKDIR /app +COPY ./requirements.txt ./requirements.txt +RUN pip3 install -r requirements.txt + +# copy all files +COPY ./ ./ + +ENTRYPOINT [ "python3","-u", "run.py"] diff --git a/brats/Dockerfile_CUDA b/brats/Dockerfile_CUDA new file mode 100644 index 0000000..b3c415b --- /dev/null +++ b/brats/Dockerfile_CUDA @@ -0,0 +1,27 @@ +# for a GPU app use this Dockerfile, delete the Dockerfile_CPU then. +FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04 + +# fill in your info here +LABEL author="chuck@norris.org" +LABEL application="your application name" +LABEL maintainer="chuck@norris.org" +# specify version here, if possible use semantic versioning +LABEL version="0.0.1" +LABEL status="beta" + +# basic +RUN apt-get -y update && apt -y full-upgrade && apt-get -y install apt-utils wget git tar build-essential curl nano + +# install python 3.6.9 +RUN apt-get update -y && apt-get install -y python3-pip python3-dev + +# install all python requirements +WORKDIR /app +COPY ./requirements.txt ./requirements.txt +RUN pip3 install -r requirements.txt + +# copy all files +COPY ./ ./ +RUN pip3 install -U python-dotenv + +ENTRYPOINT [ "python3","-u", "run.py"] diff --git a/brats/LICENSE b/brats/LICENSE new file mode 100644 index 0000000..29ebfa5 --- /dev/null +++ b/brats/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. \ No newline at end of file diff --git a/brats/README.md b/brats/README.md new file mode 100644 index 0000000..cf00b0f --- /dev/null +++ b/brats/README.md @@ -0,0 +1,35 @@ +# BraTS Challenge 2020 - MLCube integration + +Original implementation: ["BraTS Instructions Repo"](https://github.com/BraTS/Instructions) + +## Dataset + +Please refer to the [BraTS challenge page](http://braintumorsegmentation.org/) and follow the instructions in the data section. + +## Project setup + +```bash +# Create Python environment and install MLCube Docker runner +virtualenv -p python3 ./env && source ./env/bin/activate && pip install mlcube-docker + +# Fetch the boston housing example from GitHub +git clone https://github.com/mlcommons/mlcube_examples && cd ./mlcube_examples +git fetch origin pull/xx/head:feature/brats && git checkout feature/brats +cd ./brats +``` + +## Tasks execution + +```bash +# Run implementation with CPU support. +mlcube run --mlcube=mlcube_cpu.yaml --task=run + +# Run implementation with GPU support. +mlcube run --mlcube=mlcube_gpu.yaml --task=run +``` + +We are targeting pull-type installation, so MLCube images should be available on Docker Hub. If not, try this: + +```Bash +mlcube run ... -Pdocker.build_strategy=always +``` diff --git a/brats/mlcube_cpu.yaml b/brats/mlcube_cpu.yaml new file mode 100644 index 0000000..fb2d6b9 --- /dev/null +++ b/brats/mlcube_cpu.yaml @@ -0,0 +1,22 @@ +name: MLCommons Brats +description: MLCommons Brats integration +authors: + - {name: "MLCommons Best Practices Working Group"} + +platform: + accelerator_count: 0 + +docker: + # Image name. + image: mlcommons/brats_cpu:0.0.1 + # Docker build context relative to $MLCUBE_ROOT. Default is `build`. + build_context: "." + # Docker file name within docker build context, default is `Dockerfile`. + build_file: "Dockerfile_CPU" + +tasks: + run: + # Run implementation + parameters: + inputs: {data_dir: data/} + outputs: {results_dir: data/results/} diff --git a/brats/mlcube_gpu.yaml b/brats/mlcube_gpu.yaml new file mode 100644 index 0000000..73a0a70 --- /dev/null +++ b/brats/mlcube_gpu.yaml @@ -0,0 +1,22 @@ +name: MLCommons Brats +description: MLCommons Brats integration +authors: + - {name: "MLCommons Best Practices Working Group"} + +platform: + accelerator_count: 0 + +docker: + # Image name. + image: mlcommons/brats_gpu:0.0.1 + # Docker build context relative to $MLCUBE_ROOT. Default is `build`. + build_context: "." + # Docker file name within docker build context, default is `Dockerfile`. + build_file: "Dockerfile_GPU" + +tasks: + run: + # Run implementation + parameters: + inputs: {data_dir: data/} + outputs: {results_dir: data/results/} diff --git a/brats/requirements.txt b/brats/requirements.txt new file mode 100644 index 0000000..025ea32 --- /dev/null +++ b/brats/requirements.txt @@ -0,0 +1 @@ +python-dotenv==0.12.0 diff --git a/brats/run.py b/brats/run.py new file mode 100644 index 0000000..1bd3399 --- /dev/null +++ b/brats/run.py @@ -0,0 +1,21 @@ +"""Load code""" +import argparse +from src.amazing_logic import run_code + +parser = argparse.ArgumentParser() +parser.add_argument( + "--data_dir", + type=str, + default=None, + help="Path to dataset.", +) +parser.add_argument( + "--results_dir", + type=str, + default=None, + help="Path to output folder.", +) +args, _unkown = parser.parse_known_args() + +# execute +run_code(args) diff --git a/brats/src/__init__.py b/brats/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/brats/src/amazing_logic.py b/brats/src/amazing_logic.py new file mode 100644 index 0000000..f366d13 --- /dev/null +++ b/brats/src/amazing_logic.py @@ -0,0 +1,38 @@ +"""Logic file""" +import os +from shutil import copyfile +from dotenv import dotenv_values +from src.utils.utilities import helper + +config = dotenv_values(".env") +APPLICATION_NAME = config["APPLICATION_NAME"] +APPLICATION_VERSION = config["APPLICATION_VERSION"] +INPUT_FOLDER = config["INPUT_FOLDER"] +OUTPUT_FOLDER = config["OUTPUT_FOLDER"] + + +def logic_wrapper(args): + """Edit your logic here""" + if args.data_dir is not None: + INPUT_FOLDER = args.data_dir + input_file = os.path.normpath(INPUT_FOLDER + "/something_t1.nii.gz") + # ... do the same for t1c, flair and t2 here + if args.results_dir is not None: + OUTPUT_FOLDER = args.results_dir + output_file = os.path.normpath(OUTPUT_FOLDER + "/something_seg.nii.gz") + + # copy paste your amazing logic here + print("wrapper: I can feel the magic happening..it feels like a little sun rising inside me!") + + # example logic + copyfile(input_file, output_file) + helper() + + +def run_code(args): + """Main function""" + print("*** code execution started:", + APPLICATION_NAME, "version:", APPLICATION_VERSION, "! ***") + logic_wrapper(args) + print("*** code execution finished:", + APPLICATION_NAME, "version:", APPLICATION_VERSION, "! ***") diff --git a/brats/src/utils/__init__.py b/brats/src/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/brats/src/utils/utilities.py b/brats/src/utils/utilities.py new file mode 100644 index 0000000..1d63eb1 --- /dev/null +++ b/brats/src/utils/utilities.py @@ -0,0 +1,4 @@ +"""utility functions here""" +def helper(): + """helper function""" + print("helper: I am so useful it hurts.") diff --git a/brats/workspace/data/results/.dockerignore b/brats/workspace/data/results/.dockerignore new file mode 100644 index 0000000..216374c --- /dev/null +++ b/brats/workspace/data/results/.dockerignore @@ -0,0 +1 @@ +output.nii.gz diff --git a/brats/workspace/data/results/.gitignore b/brats/workspace/data/results/.gitignore new file mode 100644 index 0000000..331cf24 --- /dev/null +++ b/brats/workspace/data/results/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!.dockerignore diff --git a/brats/workspace/data/something_flair.nii.gz b/brats/workspace/data/something_flair.nii.gz new file mode 100644 index 0000000..29f3f81 --- /dev/null +++ b/brats/workspace/data/something_flair.nii.gz @@ -0,0 +1 @@ +I am a standardized compressed nifti file! \ No newline at end of file diff --git a/brats/workspace/data/something_survival_metadata.csv b/brats/workspace/data/something_survival_metadata.csv new file mode 100644 index 0000000..cbd0629 --- /dev/null +++ b/brats/workspace/data/something_survival_metadata.csv @@ -0,0 +1,14 @@ +exam_id,age,resection_status +something,NA,NA + +First column: exam name, string for the exam name +Second Column: Age as a float or NA for missing +Third Column: resection status as NA for missing, GTR/STR as a string + +ATTENTION: note the slightly changed column names in comparison to what you received for testing + +Example for a case without missing data: + +exam_id,age,resection_status +BraTS20_Testing_015,51.449,GTR + diff --git a/brats/workspace/data/something_t1.nii.gz b/brats/workspace/data/something_t1.nii.gz new file mode 100644 index 0000000..29f3f81 --- /dev/null +++ b/brats/workspace/data/something_t1.nii.gz @@ -0,0 +1 @@ +I am a standardized compressed nifti file! \ No newline at end of file diff --git a/brats/workspace/data/something_t1ce.nii.gz b/brats/workspace/data/something_t1ce.nii.gz new file mode 100644 index 0000000..29f3f81 --- /dev/null +++ b/brats/workspace/data/something_t1ce.nii.gz @@ -0,0 +1 @@ +I am a standardized compressed nifti file! \ No newline at end of file diff --git a/brats/workspace/data/someting_t2.nii.gz b/brats/workspace/data/someting_t2.nii.gz new file mode 100644 index 0000000..29f3f81 --- /dev/null +++ b/brats/workspace/data/someting_t2.nii.gz @@ -0,0 +1 @@ +I am a standardized compressed nifti file! \ No newline at end of file From 40d335c2e51fab50cb95b7206db2bcfc55752fbd Mon Sep 17 00:00:00 2001 From: David Jurado Date: Tue, 11 Jan 2022 13:06:54 -0500 Subject: [PATCH 02/28] Fix README --- brats/README.md | 2 +- brats/mlcube_gpu.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brats/README.md b/brats/README.md index cf00b0f..38c29d6 100644 --- a/brats/README.md +++ b/brats/README.md @@ -14,7 +14,7 @@ virtualenv -p python3 ./env && source ./env/bin/activate && pip install mlcube-d # Fetch the boston housing example from GitHub git clone https://github.com/mlcommons/mlcube_examples && cd ./mlcube_examples -git fetch origin pull/xx/head:feature/brats && git checkout feature/brats +git fetch origin pull/39/head:feature/brats && git checkout feature/brats cd ./brats ``` diff --git a/brats/mlcube_gpu.yaml b/brats/mlcube_gpu.yaml index 73a0a70..9050077 100644 --- a/brats/mlcube_gpu.yaml +++ b/brats/mlcube_gpu.yaml @@ -12,7 +12,7 @@ docker: # Docker build context relative to $MLCUBE_ROOT. Default is `build`. build_context: "." # Docker file name within docker build context, default is `Dockerfile`. - build_file: "Dockerfile_GPU" + build_file: "Dockerfile_CUDA" tasks: run: From 1e014cbd7e23e87353802b434f17c82f67845903 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 11 Feb 2022 11:34:25 -0500 Subject: [PATCH 03/28] Refactor folder project to make it more understandable --- brats/.env | 13 ---- brats/Dockerfile_CPU | 4 +- brats/{Dockerfile_CUDA => Dockerfile_GPU} | 4 +- brats/README.md | 69 +++++++++++++++++++ brats/mlcube.py | 61 ++++++++++++++++ brats/mlcube_cpu.yaml | 9 ++- brats/mlcube_gpu.yaml | 11 ++- brats/requirements.txt | 3 +- brats/run.py | 21 ------ brats/src/amazing_logic.py | 38 ---------- brats/src/my_logic.py | 32 +++++++++ brats/src/utils/utilities.py | 2 +- brats/workspace/data/results/.dockerignore | 2 +- brats/workspace/data/something_flair.nii.gz | 1 - .../data/something_survival_metadata.csv | 14 ---- brats/workspace/data/something_t1ce.nii.gz | 1 - brats/workspace/data/someting_t2.nii.gz | 1 - brats/workspace/parameters.yaml | 9 +++ 18 files changed, 194 insertions(+), 101 deletions(-) delete mode 100644 brats/.env rename brats/{Dockerfile_CUDA => Dockerfile_GPU} (86%) create mode 100644 brats/mlcube.py delete mode 100644 brats/run.py delete mode 100644 brats/src/amazing_logic.py create mode 100644 brats/src/my_logic.py delete mode 100644 brats/workspace/data/something_flair.nii.gz delete mode 100644 brats/workspace/data/something_survival_metadata.csv delete mode 100644 brats/workspace/data/something_t1ce.nii.gz delete mode 100644 brats/workspace/data/someting_t2.nii.gz create mode 100644 brats/workspace/parameters.yaml diff --git a/brats/.env b/brats/.env deleted file mode 100644 index 6dc4217..0000000 --- a/brats/.env +++ /dev/null @@ -1,13 +0,0 @@ -# author info -AUTHOR_NAME = "Chuck Norris" -AUTHOR_EMAIL = "chuck@norris.org" -# put your app name here -APPLICATION_NAME = "AMAZING APPLICATION" -# specify version here, if possible use semantic versioning -APPLICATION_VERSION = "0.0.1" - -INPUT_FOLDER ="workspace/data/" -OUTPUT_FOLDER ="workspace/data/results/" - -INPUT_FOLDER_DOCKER="/app/data/" -OUTPUT_FOLDER_DOCKER ="/app/data/results/" \ No newline at end of file diff --git a/brats/Dockerfile_CPU b/brats/Dockerfile_CPU index 7a60a09..436cf7c 100644 --- a/brats/Dockerfile_CPU +++ b/brats/Dockerfile_CPU @@ -1,4 +1,4 @@ -# for a CPU app use this Dockerfile, delete the Dockerfile_CUDA then. +# for a CPU app use this Dockerfile. FROM python:3.8-buster # fill in your info here @@ -19,4 +19,4 @@ RUN pip3 install -r requirements.txt # copy all files COPY ./ ./ -ENTRYPOINT [ "python3","-u", "run.py"] +ENTRYPOINT [ "python3", "mlcube.py"] diff --git a/brats/Dockerfile_CUDA b/brats/Dockerfile_GPU similarity index 86% rename from brats/Dockerfile_CUDA rename to brats/Dockerfile_GPU index b3c415b..bc2c233 100644 --- a/brats/Dockerfile_CUDA +++ b/brats/Dockerfile_GPU @@ -1,4 +1,4 @@ -# for a GPU app use this Dockerfile, delete the Dockerfile_CPU then. +# for a GPU app use this Dockerfile. FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04 # fill in your info here @@ -24,4 +24,4 @@ RUN pip3 install -r requirements.txt COPY ./ ./ RUN pip3 install -U python-dotenv -ENTRYPOINT [ "python3","-u", "run.py"] +ENTRYPOINT [ "python3", "mlcube.py"] diff --git a/brats/README.md b/brats/README.md index 38c29d6..c79dcba 100644 --- a/brats/README.md +++ b/brats/README.md @@ -18,6 +18,75 @@ git fetch origin pull/39/head:feature/brats && git checkout feature/brats cd ./brats ``` +## Important files + +These are the most important files on this project: + +```bash +├── Dockerfile_CPU # Docker file with instructions to create the image with for CPU version. +├── Dockerfile_GPU # Docker file with instructions to create the image with for CPU version. +├── mlcube.py # Python entrypoint used by MLCube, contains the logic for MLCube tasks. +├── mlcube_cpu.yaml # MLCube CPU configuration, defines the project, author, platform, docker and tasks. +├── mlcube_gpu.yaml # MLCube GPU configuration, here the difference is the target dockerfile. +├── requirements.txt # Python requirements needed to run the project inside Docker. +├── src +│ ├── my_logic.py # Python file that contains the main logic of the project. +│ └── utils +│ └── utilities.py # Python utilities file that store useful functions. +└── workspace + └── parameters.yaml # File containing all extra parameters. +``` +## How to modify this project + +You can change each file describe above in order to add your own umplementation. + +### Requirements file + +In this file (`requirements.txt`) you can add all the python dependencies needed for running your implementation, this dependencies will be install during the creating of the docker image, this happens when you run the ```mlcube run ...``` command. +### Dockerfile + +You can use both, CPU or GPU version for the dockerfile (`Dockerfile_CPU`, `Dockerfile_GPU`), also, you can add or modify any steps inside the file, this comes handy when you need to install some OS dependencies or even when you want to change the base docker image, inside the file you can find some information about the existing steps. + + +### Parameters file + +This is a yaml file (`parameters.yaml`)that contains all extra parameters that are not files or directories, for example, here you can place all the hyperparameters that you will use for training a model. This file will be pass as a **input parameter** in the MLCube tasks and then it will be read inside the MLCube container. + +### MLCube yaml file + +In these files (`mlcube_cpu`, `mlcube_gpu`) you can find the instructions about the docker image and platform that wil be used, information about the project (name, description, authors), and also the tasks defined for the project. + +In the existing implementation you will find 2 tasks: + +* example: + + It only takes one input parameter: parameters file. + This task read one specific parameters from the parameters file () and then print the value of the parameter. + +* run: + + This task take the followin parameters: + + * Input parameters: + * input_folder: folder path containing input data + * parameters_file: Extra parameters + * Output parameters: + * output_folder: folder path where output data will be stored + + This task take the input data, "process it" and then save the output result in the output_folder, it also prints some information from the extra parameters. + + +### MLCube python file + +The `mlcube.py` file is the handler file and entrypoint described in the dockerfile, here you can find all the logic related on how to process each MLCube task. If you want to add a new task first you must define it inside the `mlcube.yaml` file with its input and output parameters and then you need to add the logic to handle this new task inside the `mlcube.py` file. + +### Main logic file + +The `my_logic.py` file contains the main logic of the project, you can modify this file and write your implementation here, this logic file is called from the `mlcube.py` file and there are other ways to link your implementation and shown in the [MLCube examples repo](https://github.com/mlcommons/mlcube_examples). + +### Utilities file + +In the `utilities.py` file you can add some functions that will be useful for your main implementation, in this case, the functions from the utilities file are used inside the main logic file. ## Tasks execution ```bash diff --git a/brats/mlcube.py b/brats/mlcube.py new file mode 100644 index 0000000..78a9871 --- /dev/null +++ b/brats/mlcube.py @@ -0,0 +1,61 @@ +"""MLCube handler file""" +import os +import typer +import yaml +from src.my_logic import run_code + +app = typer.Typer() + + +class ExampleTask(object): + """Example task Class + It reads the content of the parameters file and then + prints "MY_NEW_PARAMETER_EXAMPLE".""" + + @staticmethod + def run_example(parameters_file: str) -> None: + + # Load parameters from the paramters file + with open(parameters_file, "r") as stream: + parameters = yaml.safe_load(stream) + + print("This is my new parameter example:") + print(parameters["MY_NEW_PARAMETER_EXAMPLE"]) + + +class RunTask(object): + """Run task Class + It defines the environment variables: + input_folder: Directory path to dataset + output_folder: Directory path to final results + All other parameters are defined in parameters_file + Then executes the run_code method inside my_logic script""" + + @staticmethod + def run(input_folder: str, output_folder: str, parameters_file: str) -> None: + + # Load parameters from the paramters file + with open(parameters_file, "r") as stream: + parameters = yaml.safe_load(stream) + + application_name = parameters["APPLICATION_NAME"] + application_version = parameters["APPLICATION_VERSION"] + run_code(input_folder, output_folder, application_name, application_version) + + +@app.command("example") +def example(parameters_file: str = typer.Option(..., "--parameters_file")): + ExampleTask.run_example(parameters_file) + + +@app.command("run") +def run( + input_folder: str = typer.Option(..., "--input_folder"), + output_folder: str = typer.Option(..., "--output_folder"), + parameters_file: str = typer.Option(..., "--parameters_file") +): + RunTask.run(input_folder, output_folder, parameters_file) + + +if __name__ == "__main__": + app() diff --git a/brats/mlcube_cpu.yaml b/brats/mlcube_cpu.yaml index fb2d6b9..a67a4f2 100644 --- a/brats/mlcube_cpu.yaml +++ b/brats/mlcube_cpu.yaml @@ -15,8 +15,13 @@ docker: build_file: "Dockerfile_CPU" tasks: + example: + # Run implementation + parameters: + inputs: {parameters_file: {type: file, default: parameters.yaml}} + run: # Run implementation parameters: - inputs: {data_dir: data/} - outputs: {results_dir: data/results/} + inputs: {input_folder: data/, parameters_file: {type: file, default: parameters.yaml}} + outputs: {output_folder: data/results/} diff --git a/brats/mlcube_gpu.yaml b/brats/mlcube_gpu.yaml index 9050077..7d875a5 100644 --- a/brats/mlcube_gpu.yaml +++ b/brats/mlcube_gpu.yaml @@ -12,11 +12,16 @@ docker: # Docker build context relative to $MLCUBE_ROOT. Default is `build`. build_context: "." # Docker file name within docker build context, default is `Dockerfile`. - build_file: "Dockerfile_CUDA" + build_file: "Dockerfile_GPU" tasks: + example: + # Run implementation + parameters: + inputs: {parameters_file: {type: file, default: parameters.yaml}} + run: # Run implementation parameters: - inputs: {data_dir: data/} - outputs: {results_dir: data/results/} + inputs: {input_folder: data/, parameters_file: {type: file, default: parameters.yaml}} + outputs: {output_folder: data/results/} diff --git a/brats/requirements.txt b/brats/requirements.txt index 025ea32..8d2d45a 100644 --- a/brats/requirements.txt +++ b/brats/requirements.txt @@ -1 +1,2 @@ -python-dotenv==0.12.0 +PyYAML +typer \ No newline at end of file diff --git a/brats/run.py b/brats/run.py deleted file mode 100644 index 1bd3399..0000000 --- a/brats/run.py +++ /dev/null @@ -1,21 +0,0 @@ -"""Load code""" -import argparse -from src.amazing_logic import run_code - -parser = argparse.ArgumentParser() -parser.add_argument( - "--data_dir", - type=str, - default=None, - help="Path to dataset.", -) -parser.add_argument( - "--results_dir", - type=str, - default=None, - help="Path to output folder.", -) -args, _unkown = parser.parse_known_args() - -# execute -run_code(args) diff --git a/brats/src/amazing_logic.py b/brats/src/amazing_logic.py deleted file mode 100644 index f366d13..0000000 --- a/brats/src/amazing_logic.py +++ /dev/null @@ -1,38 +0,0 @@ -"""Logic file""" -import os -from shutil import copyfile -from dotenv import dotenv_values -from src.utils.utilities import helper - -config = dotenv_values(".env") -APPLICATION_NAME = config["APPLICATION_NAME"] -APPLICATION_VERSION = config["APPLICATION_VERSION"] -INPUT_FOLDER = config["INPUT_FOLDER"] -OUTPUT_FOLDER = config["OUTPUT_FOLDER"] - - -def logic_wrapper(args): - """Edit your logic here""" - if args.data_dir is not None: - INPUT_FOLDER = args.data_dir - input_file = os.path.normpath(INPUT_FOLDER + "/something_t1.nii.gz") - # ... do the same for t1c, flair and t2 here - if args.results_dir is not None: - OUTPUT_FOLDER = args.results_dir - output_file = os.path.normpath(OUTPUT_FOLDER + "/something_seg.nii.gz") - - # copy paste your amazing logic here - print("wrapper: I can feel the magic happening..it feels like a little sun rising inside me!") - - # example logic - copyfile(input_file, output_file) - helper() - - -def run_code(args): - """Main function""" - print("*** code execution started:", - APPLICATION_NAME, "version:", APPLICATION_VERSION, "! ***") - logic_wrapper(args) - print("*** code execution finished:", - APPLICATION_NAME, "version:", APPLICATION_VERSION, "! ***") diff --git a/brats/src/my_logic.py b/brats/src/my_logic.py new file mode 100644 index 0000000..c237d07 --- /dev/null +++ b/brats/src/my_logic.py @@ -0,0 +1,32 @@ +"""Logic file""" +import os +from shutil import copyfile +from src.utils.utilities import helper + + +def logic_wrapper(input_folder, output_folder): + """Edit your logic here""" + input_file = os.path.normpath(input_folder + "/something_t1.nii.gz") + output_file = os.path.normpath(output_folder + "/something_seg.nii.gz") + + # copy paste your logic here + print("wrapper: Here you can place your own logic") + + # example logic + copyfile(input_file, output_file) + helper() + + +def run_code(input_folder, output_folder, application_name, application_version): + """Main function""" + print( + "*** code execution started:", application_name, + "version:", application_version, "! ***", + ) + + logic_wrapper(input_folder, output_folder) + + print( + "*** code execution finished:", application_name, + "version:", application_version, "! ***", + ) diff --git a/brats/src/utils/utilities.py b/brats/src/utils/utilities.py index 1d63eb1..da685e7 100644 --- a/brats/src/utils/utilities.py +++ b/brats/src/utils/utilities.py @@ -1,4 +1,4 @@ """utility functions here""" def helper(): """helper function""" - print("helper: I am so useful it hurts.") + print("helper: Here you can store all your utility functions") diff --git a/brats/workspace/data/results/.dockerignore b/brats/workspace/data/results/.dockerignore index 216374c..4462c1c 100644 --- a/brats/workspace/data/results/.dockerignore +++ b/brats/workspace/data/results/.dockerignore @@ -1 +1 @@ -output.nii.gz +*.nii.gz diff --git a/brats/workspace/data/something_flair.nii.gz b/brats/workspace/data/something_flair.nii.gz deleted file mode 100644 index 29f3f81..0000000 --- a/brats/workspace/data/something_flair.nii.gz +++ /dev/null @@ -1 +0,0 @@ -I am a standardized compressed nifti file! \ No newline at end of file diff --git a/brats/workspace/data/something_survival_metadata.csv b/brats/workspace/data/something_survival_metadata.csv deleted file mode 100644 index cbd0629..0000000 --- a/brats/workspace/data/something_survival_metadata.csv +++ /dev/null @@ -1,14 +0,0 @@ -exam_id,age,resection_status -something,NA,NA - -First column: exam name, string for the exam name -Second Column: Age as a float or NA for missing -Third Column: resection status as NA for missing, GTR/STR as a string - -ATTENTION: note the slightly changed column names in comparison to what you received for testing - -Example for a case without missing data: - -exam_id,age,resection_status -BraTS20_Testing_015,51.449,GTR - diff --git a/brats/workspace/data/something_t1ce.nii.gz b/brats/workspace/data/something_t1ce.nii.gz deleted file mode 100644 index 29f3f81..0000000 --- a/brats/workspace/data/something_t1ce.nii.gz +++ /dev/null @@ -1 +0,0 @@ -I am a standardized compressed nifti file! \ No newline at end of file diff --git a/brats/workspace/data/someting_t2.nii.gz b/brats/workspace/data/someting_t2.nii.gz deleted file mode 100644 index 29f3f81..0000000 --- a/brats/workspace/data/someting_t2.nii.gz +++ /dev/null @@ -1 +0,0 @@ -I am a standardized compressed nifti file! \ No newline at end of file diff --git a/brats/workspace/parameters.yaml b/brats/workspace/parameters.yaml new file mode 100644 index 0000000..211fd56 --- /dev/null +++ b/brats/workspace/parameters.yaml @@ -0,0 +1,9 @@ +# Here you can define new parameters +MY_NEW_PARAMETER_EXAMPLE: "*Example*" +# author info +AUTHOR_NAME: "Chuck Norris" +AUTHOR_EMAIL: "chuck@norris.org" +# put your app name here +APPLICATION_NAME: "AMAZING APPLICATION" +# specify version here, if possible use semantic versioning +APPLICATION_VERSION: "0.0.1" \ No newline at end of file From 3a1d28cee1323880411c33748f6f85895a64e42b Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 11 Feb 2022 11:45:57 -0500 Subject: [PATCH 04/28] Add project workflow diagram --- brats/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brats/README.md b/brats/README.md index c79dcba..46b1e03 100644 --- a/brats/README.md +++ b/brats/README.md @@ -36,6 +36,11 @@ These are the most important files on this project: └── workspace └── parameters.yaml # File containing all extra parameters. ``` + +## Project workflow + +![MLCube workflow](https://i.imgur.com/qXRp3Tb.png) + ## How to modify this project You can change each file describe above in order to add your own umplementation. From 3a8bae6fde3c2b58f0ff4f409ae4096bb7d584ab Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 11 Feb 2022 12:10:58 -0500 Subject: [PATCH 05/28] Fix typos --- brats/README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/brats/README.md b/brats/README.md index 46b1e03..8cbdeec 100644 --- a/brats/README.md +++ b/brats/README.md @@ -23,8 +23,8 @@ cd ./brats These are the most important files on this project: ```bash -├── Dockerfile_CPU # Docker file with instructions to create the image with for CPU version. -├── Dockerfile_GPU # Docker file with instructions to create the image with for CPU version. +├── Dockerfile_CPU # Docker file with instructions to create the image for the CPU version. +├── Dockerfile_GPU # Docker file with instructions to create the image for the GPU version. ├── mlcube.py # Python entrypoint used by MLCube, contains the logic for MLCube tasks. ├── mlcube_cpu.yaml # MLCube CPU configuration, defines the project, author, platform, docker and tasks. ├── mlcube_gpu.yaml # MLCube GPU configuration, here the difference is the target dockerfile. @@ -32,7 +32,7 @@ These are the most important files on this project: ├── src │ ├── my_logic.py # Python file that contains the main logic of the project. │ └── utils -│ └── utilities.py # Python utilities file that store useful functions. +│ └── utilities.py # Python utilities file that stores useful functions. └── workspace └── parameters.yaml # File containing all extra parameters. ``` @@ -43,11 +43,11 @@ These are the most important files on this project: ## How to modify this project -You can change each file describe above in order to add your own umplementation. +You can change each file described above in order to add your own implementation. ### Requirements file -In this file (`requirements.txt`) you can add all the python dependencies needed for running your implementation, this dependencies will be install during the creating of the docker image, this happens when you run the ```mlcube run ...``` command. +In this file (`requirements.txt`) you can add all the python dependencies needed for running your implementation, these dependencies will be installed during the creation of the docker image, this happens when you run the ```mlcube run ...``` command. ### Dockerfile You can use both, CPU or GPU version for the dockerfile (`Dockerfile_CPU`, `Dockerfile_GPU`), also, you can add or modify any steps inside the file, this comes handy when you need to install some OS dependencies or even when you want to change the base docker image, inside the file you can find some information about the existing steps. @@ -55,22 +55,22 @@ You can use both, CPU or GPU version for the dockerfile (`Dockerfile_CPU`, `Dock ### Parameters file -This is a yaml file (`parameters.yaml`)that contains all extra parameters that are not files or directories, for example, here you can place all the hyperparameters that you will use for training a model. This file will be pass as a **input parameter** in the MLCube tasks and then it will be read inside the MLCube container. +This is a yaml file (`parameters.yaml`)that contains all extra parameters that aren't files or directories, for example, here you can place all the hyperparameters that you will use for training a model. This file will be passed as an **input parameter** in the MLCube tasks and then it will be read inside the MLCube container. ### MLCube yaml file -In these files (`mlcube_cpu`, `mlcube_gpu`) you can find the instructions about the docker image and platform that wil be used, information about the project (name, description, authors), and also the tasks defined for the project. +In these files (`mlcube_cpu`, `mlcube_gpu`) you can find the instructions about the docker image and platform that will be used, information about the project (name, description, authors), and also the tasks defined for the project. In the existing implementation you will find 2 tasks: * example: It only takes one input parameter: parameters file. - This task read one specific parameters from the parameters file () and then print the value of the parameter. + This task reads one specific parameter from the parameters file () and then prints the value of the parameter. * run: - This task take the followin parameters: + This task takes the following parameters: * Input parameters: * input_folder: folder path containing input data @@ -78,12 +78,12 @@ In the existing implementation you will find 2 tasks: * Output parameters: * output_folder: folder path where output data will be stored - This task take the input data, "process it" and then save the output result in the output_folder, it also prints some information from the extra parameters. + This task takes the input data, "process it" and then save the output result in the output_folder, it also prints some information from the extra parameters. ### MLCube python file -The `mlcube.py` file is the handler file and entrypoint described in the dockerfile, here you can find all the logic related on how to process each MLCube task. If you want to add a new task first you must define it inside the `mlcube.yaml` file with its input and output parameters and then you need to add the logic to handle this new task inside the `mlcube.py` file. +The `mlcube.py` file is the handler file and entrypoint described in the dockerfile, here you can find all the logic related to how to process each MLCube task. If you want to add a new task first you must define it inside the `mlcube.yaml` file with its input and output parameters and then you need to add the logic to handle this new task inside the `mlcube.py` file. ### Main logic file From b9d2b2d3f43207cd396ed9301d44ce17505f2a0a Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 11 Feb 2022 13:15:34 -0500 Subject: [PATCH 06/28] Add missing command --- brats/README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/brats/README.md b/brats/README.md index 8cbdeec..aa1211b 100644 --- a/brats/README.md +++ b/brats/README.md @@ -95,10 +95,16 @@ In the `utilities.py` file you can add some functions that will be useful for yo ## Tasks execution ```bash -# Run implementation with CPU support. +# Run example task with CPU support. +mlcube run --mlcube=mlcube_cpu.yaml --task=example + +# Run main task with CPU support. mlcube run --mlcube=mlcube_cpu.yaml --task=run -# Run implementation with GPU support. +# Run example task with GPU support. +mlcube run --mlcube=mlcube_gpu.yaml --task=example + +# Run main task with GPU support. mlcube run --mlcube=mlcube_gpu.yaml --task=run ``` From 6c9536ca955fc5e22ccdc40ae4cac27bb0aad952 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Wed, 16 Feb 2022 15:49:16 -0500 Subject: [PATCH 07/28] Refactor project to match MedPerf specifications --- brats/{ => mlcube}/mlcube_cpu.yaml | 6 +++--- brats/{ => mlcube}/mlcube_gpu.yaml | 6 +++--- .../workspace/data/results/.dockerignore | 0 .../workspace/data/results/.gitignore | 0 .../workspace/data/something_t1.nii.gz | 0 brats/{ => mlcube}/workspace/parameters.yaml | 0 brats/{ => project}/Dockerfile_CPU | 0 brats/{ => project}/Dockerfile_GPU | 0 brats/{ => project}/LICENSE | 0 brats/{ => project}/mlcube.py | 16 ++++++++-------- brats/{ => project}/requirements.txt | 0 brats/{ => project}/src/__init__.py | 0 brats/{ => project}/src/my_logic.py | 0 brats/{ => project}/src/utils/__init__.py | 0 brats/{ => project}/src/utils/utilities.py | 0 15 files changed, 14 insertions(+), 14 deletions(-) rename brats/{ => mlcube}/mlcube_cpu.yaml (83%) rename brats/{ => mlcube}/mlcube_gpu.yaml (83%) rename brats/{ => mlcube}/workspace/data/results/.dockerignore (100%) rename brats/{ => mlcube}/workspace/data/results/.gitignore (100%) rename brats/{ => mlcube}/workspace/data/something_t1.nii.gz (100%) rename brats/{ => mlcube}/workspace/parameters.yaml (100%) rename brats/{ => project}/Dockerfile_CPU (100%) rename brats/{ => project}/Dockerfile_GPU (100%) rename brats/{ => project}/LICENSE (100%) rename brats/{ => project}/mlcube.py (78%) rename brats/{ => project}/requirements.txt (100%) rename brats/{ => project}/src/__init__.py (100%) rename brats/{ => project}/src/my_logic.py (100%) rename brats/{ => project}/src/utils/__init__.py (100%) rename brats/{ => project}/src/utils/utilities.py (100%) diff --git a/brats/mlcube_cpu.yaml b/brats/mlcube/mlcube_cpu.yaml similarity index 83% rename from brats/mlcube_cpu.yaml rename to brats/mlcube/mlcube_cpu.yaml index a67a4f2..00b932f 100644 --- a/brats/mlcube_cpu.yaml +++ b/brats/mlcube/mlcube_cpu.yaml @@ -10,7 +10,7 @@ docker: # Image name. image: mlcommons/brats_cpu:0.0.1 # Docker build context relative to $MLCUBE_ROOT. Default is `build`. - build_context: "." + build_context: "../project" # Docker file name within docker build context, default is `Dockerfile`. build_file: "Dockerfile_CPU" @@ -20,8 +20,8 @@ tasks: parameters: inputs: {parameters_file: {type: file, default: parameters.yaml}} - run: + infer: # Run implementation parameters: - inputs: {input_folder: data/, parameters_file: {type: file, default: parameters.yaml}} + inputs: {data_path: data/, parameters_file: parameters.yaml} outputs: {output_folder: data/results/} diff --git a/brats/mlcube_gpu.yaml b/brats/mlcube/mlcube_gpu.yaml similarity index 83% rename from brats/mlcube_gpu.yaml rename to brats/mlcube/mlcube_gpu.yaml index 7d875a5..eb18d0f 100644 --- a/brats/mlcube_gpu.yaml +++ b/brats/mlcube/mlcube_gpu.yaml @@ -10,7 +10,7 @@ docker: # Image name. image: mlcommons/brats_gpu:0.0.1 # Docker build context relative to $MLCUBE_ROOT. Default is `build`. - build_context: "." + build_context: "../project" # Docker file name within docker build context, default is `Dockerfile`. build_file: "Dockerfile_GPU" @@ -20,8 +20,8 @@ tasks: parameters: inputs: {parameters_file: {type: file, default: parameters.yaml}} - run: + infer: # Run implementation parameters: - inputs: {input_folder: data/, parameters_file: {type: file, default: parameters.yaml}} + inputs: {data_path: data/, parameters_file: parameters.yaml} outputs: {output_folder: data/results/} diff --git a/brats/workspace/data/results/.dockerignore b/brats/mlcube/workspace/data/results/.dockerignore similarity index 100% rename from brats/workspace/data/results/.dockerignore rename to brats/mlcube/workspace/data/results/.dockerignore diff --git a/brats/workspace/data/results/.gitignore b/brats/mlcube/workspace/data/results/.gitignore similarity index 100% rename from brats/workspace/data/results/.gitignore rename to brats/mlcube/workspace/data/results/.gitignore diff --git a/brats/workspace/data/something_t1.nii.gz b/brats/mlcube/workspace/data/something_t1.nii.gz similarity index 100% rename from brats/workspace/data/something_t1.nii.gz rename to brats/mlcube/workspace/data/something_t1.nii.gz diff --git a/brats/workspace/parameters.yaml b/brats/mlcube/workspace/parameters.yaml similarity index 100% rename from brats/workspace/parameters.yaml rename to brats/mlcube/workspace/parameters.yaml diff --git a/brats/Dockerfile_CPU b/brats/project/Dockerfile_CPU similarity index 100% rename from brats/Dockerfile_CPU rename to brats/project/Dockerfile_CPU diff --git a/brats/Dockerfile_GPU b/brats/project/Dockerfile_GPU similarity index 100% rename from brats/Dockerfile_GPU rename to brats/project/Dockerfile_GPU diff --git a/brats/LICENSE b/brats/project/LICENSE similarity index 100% rename from brats/LICENSE rename to brats/project/LICENSE diff --git a/brats/mlcube.py b/brats/project/mlcube.py similarity index 78% rename from brats/mlcube.py rename to brats/project/mlcube.py index 78a9871..8ab6cb5 100644 --- a/brats/mlcube.py +++ b/brats/project/mlcube.py @@ -23,16 +23,16 @@ def run_example(parameters_file: str) -> None: print(parameters["MY_NEW_PARAMETER_EXAMPLE"]) -class RunTask(object): +class InferTask(object): """Run task Class It defines the environment variables: - input_folder: Directory path to dataset + data_path: Directory path to dataset output_folder: Directory path to final results All other parameters are defined in parameters_file Then executes the run_code method inside my_logic script""" @staticmethod - def run(input_folder: str, output_folder: str, parameters_file: str) -> None: + def run(data_path: str, output_folder: str, parameters_file: str) -> None: # Load parameters from the paramters file with open(parameters_file, "r") as stream: @@ -40,7 +40,7 @@ def run(input_folder: str, output_folder: str, parameters_file: str) -> None: application_name = parameters["APPLICATION_NAME"] application_version = parameters["APPLICATION_VERSION"] - run_code(input_folder, output_folder, application_name, application_version) + run_code(data_path, output_folder, application_name, application_version) @app.command("example") @@ -48,13 +48,13 @@ def example(parameters_file: str = typer.Option(..., "--parameters_file")): ExampleTask.run_example(parameters_file) -@app.command("run") -def run( - input_folder: str = typer.Option(..., "--input_folder"), +@app.command("infer") +def infer( + data_path: str = typer.Option(..., "--data_path"), output_folder: str = typer.Option(..., "--output_folder"), parameters_file: str = typer.Option(..., "--parameters_file") ): - RunTask.run(input_folder, output_folder, parameters_file) + InferTask.run(data_path, output_folder, parameters_file) if __name__ == "__main__": diff --git a/brats/requirements.txt b/brats/project/requirements.txt similarity index 100% rename from brats/requirements.txt rename to brats/project/requirements.txt diff --git a/brats/src/__init__.py b/brats/project/src/__init__.py similarity index 100% rename from brats/src/__init__.py rename to brats/project/src/__init__.py diff --git a/brats/src/my_logic.py b/brats/project/src/my_logic.py similarity index 100% rename from brats/src/my_logic.py rename to brats/project/src/my_logic.py diff --git a/brats/src/utils/__init__.py b/brats/project/src/utils/__init__.py similarity index 100% rename from brats/src/utils/__init__.py rename to brats/project/src/utils/__init__.py diff --git a/brats/src/utils/utilities.py b/brats/project/src/utils/utilities.py similarity index 100% rename from brats/src/utils/utilities.py rename to brats/project/src/utils/utilities.py From 597fc445c552e9d3b27f07f1ddd0cda4a095a0ff Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Feb 2022 11:23:17 -0500 Subject: [PATCH 08/28] Refactor project and add metrics MLCube --- brats/metrics/.gitignore | 2 + brats/metrics/README.md | 98 ++++++++++ brats/metrics/mlcube/mlcube.yaml | 22 +++ .../ground_truth/BraTS_example_seg.nii.gz | Bin 0 -> 26095 bytes .../data/predictions/BraTS_example_seg.nii.gz | Bin 0 -> 26095 bytes .../metrics/mlcube/workspace/parameters.yaml | 2 + .../project/Dockerfile} | 0 brats/metrics/project/metrics.py | 172 ++++++++++++++++++ brats/metrics/project/mlcube.py | 43 +++++ brats/metrics/project/requirements.txt | 4 + brats/{ => model}/.gitignore | 0 brats/{ => model}/README.md | 50 ++--- brats/{ => model}/mlcube/mlcube_cpu.yaml | 2 +- brats/{ => model}/mlcube/mlcube_gpu.yaml | 2 +- .../workspace/data/results/.dockerignore | 0 .../mlcube/workspace/data/results/.gitignore | 0 .../mlcube/workspace/data/something_t1.nii.gz | 0 .../mlcube/workspace/parameters.yaml | 0 brats/model/project/Dockerfile_CPU | 22 +++ brats/{ => model}/project/Dockerfile_GPU | 0 brats/{ => model}/project/LICENSE | 0 brats/{ => model}/project/mlcube.py | 10 +- brats/{ => model}/project/requirements.txt | 0 brats/{ => model}/project/src/__init__.py | 0 brats/{ => model}/project/src/my_logic.py | 0 .../{ => model}/project/src/utils/__init__.py | 0 .../project/src/utils/utilities.py | 0 27 files changed, 398 insertions(+), 31 deletions(-) create mode 100644 brats/metrics/.gitignore create mode 100644 brats/metrics/README.md create mode 100644 brats/metrics/mlcube/mlcube.yaml create mode 100644 brats/metrics/mlcube/workspace/data/ground_truth/BraTS_example_seg.nii.gz create mode 100644 brats/metrics/mlcube/workspace/data/predictions/BraTS_example_seg.nii.gz create mode 100644 brats/metrics/mlcube/workspace/parameters.yaml rename brats/{project/Dockerfile_CPU => metrics/project/Dockerfile} (100%) create mode 100644 brats/metrics/project/metrics.py create mode 100644 brats/metrics/project/mlcube.py create mode 100644 brats/metrics/project/requirements.txt rename brats/{ => model}/.gitignore (100%) rename brats/{ => model}/README.md (74%) rename brats/{ => model}/mlcube/mlcube_cpu.yaml (93%) rename brats/{ => model}/mlcube/mlcube_gpu.yaml (93%) rename brats/{ => model}/mlcube/workspace/data/results/.dockerignore (100%) rename brats/{ => model}/mlcube/workspace/data/results/.gitignore (100%) rename brats/{ => model}/mlcube/workspace/data/something_t1.nii.gz (100%) rename brats/{ => model}/mlcube/workspace/parameters.yaml (100%) create mode 100644 brats/model/project/Dockerfile_CPU rename brats/{ => model}/project/Dockerfile_GPU (100%) rename brats/{ => model}/project/LICENSE (100%) rename brats/{ => model}/project/mlcube.py (81%) rename brats/{ => model}/project/requirements.txt (100%) rename brats/{ => model}/project/src/__init__.py (100%) rename brats/{ => model}/project/src/my_logic.py (100%) rename brats/{ => model}/project/src/utils/__init__.py (100%) rename brats/{ => model}/project/src/utils/utilities.py (100%) diff --git a/brats/metrics/.gitignore b/brats/metrics/.gitignore new file mode 100644 index 0000000..19b45fa --- /dev/null +++ b/brats/metrics/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +mlcube/workspace/results.yaml \ No newline at end of file diff --git a/brats/metrics/README.md b/brats/metrics/README.md new file mode 100644 index 0000000..49aa0cd --- /dev/null +++ b/brats/metrics/README.md @@ -0,0 +1,98 @@ +# BraTS Challenge 2020 - MLCube integration - Metrics + +Original implementation: ["BraTS Instructions Repo"](https://github.com/BraTS/Instructions) + +## Dataset + +Please refer to the [BraTS challenge page](http://braintumorsegmentation.org/) and follow the instructions in the data section. + +## Project setup + +```bash +# Create Python environment and install MLCube Docker runner +virtualenv -p python3 ./env && source ./env/bin/activate && pip install mlcube-docker + +# Fetch the boston housing example from GitHub +git clone https://github.com/mlcommons/mlcube_examples && cd ./mlcube_examples +git fetch origin pull/39/head:feature/brats && git checkout feature/brats +cd ./brats/metrics/mlcube +``` + +## Important files + +These are the most important files on this project: + +```bash + +├── mlcube +│ ├── mlcube.yaml # MLCube configuration file, it defines the project, author, platform, docker and tasks. +│ └── workspace +│ ├── data +│ │ ├── ground_truth +│ │ │ └── BraTS_example_seg.nii.gz # Ground truth example file +│ │ └── predictions +│ │ └── BraTS_example_seg.nii.gz # Prediction example file +│ ├── parameters.yaml +│ └── results.yaml # Final output file containing result metrics. +└── project + ├── Dockerfile # Docker file with instructions to create the image for the project. + ├── metrics.py # Python file that contains the main logic of the project. + ├── mlcube.py # Python entrypoint used by MLCube, contains the logic for MLCube tasks. + └── requirements.txt # Python requirements needed to run the project inside Docker. +``` + +## How to modify this project + +You can change each file described above in order to add your own implementation. + +### Requirements file + +In this file (`requirements.txt`) you can add all the python dependencies needed for running your implementation, these dependencies will be installed during the creation of the docker image, this happens when you run the ```mlcube run ...``` command. + +### Dockerfile + +You can use both, CPU or GPU version for the dockerfile (`Dockerfile_CPU`, `Dockerfile_GPU`), also, you can add or modify any steps inside the file, this comes handy when you need to install some OS dependencies or even when you want to change the base docker image, inside the file you can find some information about the existing steps. + +### Parameters file + +This is a yaml file (`parameters.yaml`)that contains all extra parameters that aren't files or directories, for example, here you can place all the hyperparameters that you will use for training a model. This file will be passed as an **input parameter** in the MLCube tasks and then it will be read inside the MLCube container. + +### MLCube yaml file + +In this file (`mlcube.yaml`) you can find the instructions about the docker image and platform that will be used, information about the project (name, description, authors), and also the tasks defined for the project. + +In the existing implementation you will find 1 task: + +* evaluate: + + This task takes the following parameters: + + * Input parameters: + * predictions: Folder path containing predictions + * ground_truth: Folder path containing ground truth data + * parameters_file: Extra parameters + * Output parameters: + * output_path: File path where output metrics will be stored + + This task takes the input predictions and ground truth data, perform the evaluation and then save the output result in the output_path. + +### MLCube python file + +The `mlcube.py` file is the handler file and entrypoint described in the dockerfile, here you can find all the logic related to how to process each MLCube task. If you want to add a new task first you must define it inside the `mlcube.yaml` file with its input and output parameters and then you need to add the logic to handle this new task inside the `mlcube.py` file. + +### Metrics file + +The `metrics.py` file contains the main logic of the project, you can modify this file and write your implementation here to calculate different metrics, this metrics file is called from the `mlcube.py` file and there are other ways to link your implementation and shown in the [MLCube examples repo](https://github.com/mlcommons/mlcube_examples). + +## Tasks execution + +```bash +# Run evaluate task. +mlcube run --mlcube=mlcube_cpu.yaml --task=evaluate +``` + +We are targeting pull-type installation, so MLCube images should be available on Docker Hub. If not, try this: + +```Bash +mlcube run ... -Pdocker.build_strategy=always +``` diff --git a/brats/metrics/mlcube/mlcube.yaml b/brats/metrics/mlcube/mlcube.yaml new file mode 100644 index 0000000..41c6fcc --- /dev/null +++ b/brats/metrics/mlcube/mlcube.yaml @@ -0,0 +1,22 @@ +name: MLCommons Brats metrics +description: MLCommons Brats integration for metrics +authors: + - {name: "MLCommons Best Practices Working Group"} + +platform: + accelerator_count: 0 + +docker: + # Image name. + image: mlcommons/brats_metrics:0.0.1 + # Docker build context relative to $MLCUBE_ROOT. Default is `build`. + build_context: "../project" + # Docker file name within docker build context, default is `Dockerfile`. + build_file: "Dockerfile" + +tasks: + evaluate: + # Executes a number of metrics specified by the params file + parameters: + inputs: {predictions: data/predictions/, ground_truth: data/ground_truth/, parameters_file: parameters.yaml} + outputs: {output_path: {type: "file", default: "results.yaml"}} diff --git a/brats/metrics/mlcube/workspace/data/ground_truth/BraTS_example_seg.nii.gz b/brats/metrics/mlcube/workspace/data/ground_truth/BraTS_example_seg.nii.gz new file mode 100644 index 0000000000000000000000000000000000000000..40c2c4620b070d7df0b3b07d2849c267f130d739 GIT binary patch literal 26095 zcmeHvdsI_*wtqWg?G?41H5FT}Xzxs06+~MR5W=I5<6A-%Ld5W>Rfs%7pdmzv2fRAy z9c`gg6y*_8L5L(IQ3DAia;SI}5lKYyFoX~o3W0h{_$I6 zEm?DjEV88-1K}WUIDGq>tz|?T zD9BpX^2~TQ(eaI9_Wtuf=Mk7kU><>a1m+Q#M_?X-c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Ge89@Ev*nK%s5uriJImDH~%qzso+QpUHArG(&Q$|ibP5QkgiG7 z#n~auZX4<`qM`vdxuKLg&^9zad@J@x(|dqskSrER*4NKP&j*m!6}DryJhW!>x9dqZJ|P*vB=ob{9s$s@ zVD%k{IB^NO*%jDqV*%RuInr|Qxs!nI2N`-!)V#~?t$d{1;qH*+9FmTx_{-2p^dW(2 zIKg>w(yBu#L4k_mNHHfi15pLM7pSOw6{qjk7Wy6yzb#J353(H;3^iO4euV2Zdn=P` z($2wTlNEC!a4l$*AQ|GP%L^70scewK_+`n5EU)0@H6Yv0(QDP8`7oy#27LH(iCuYL zLBc_69f#9db*)7n?y?iG&F&f0DFWlBA+WVuQc0w(NCO0Lzi3^rwc!dJTzJpS&fZv) z){*il8CP)u@mj=Ce!zdZROf8V11zblNdO>2S{^Sems!;gu11PF5a)Ab?Q1_!_|pdB zsnA5{Ve}Zpd?vnh zd`ONR2v~;bL$Jn)c5Be`ZozQVN+u2&>e#K_F+68f!_ohq0fny|2=c*9=i7Bty z1PI-@GB06$xwRKNSj>jqD5*9~${4<00#A5gBPe`BT6}1w@tDeBHasosZ^K$>$;8uZ;=3u#s?%Vt-ZiI2eib6J zi>-&lH6aMM0%sZkZAEY}H=^(_2FxB!FVeSM*qpCI6aZ3*y0rmlfmkQl(Uh2Qjk3Ve z6dOjFT5`>liLf|8J#IUsM?!tB=Hq|;gs$ID<+b)qJ(ce&ISNHnxtlM8HMZ8i{G(cb z^8^3>lb_wQn=1Fs(WZcZ|KrZzaUOwr1pdzmOcw@k{e|l;&+`ZiF!Qf@1m+Q#M_?X- zc?9MWm`7k9fq4Yx5tv6{9)WoT<`MY+9f3>M{!)h cfq4Yx5tv6{ZV@ np.ndarray: + """ + Calculate Dice score for data batch. + Params: + probobilities: model outputs after activation function. + truth: truth values. + threshold: threshold for probabilities. + eps: additive to refine the estimate. + Returns: dice score aka f1. + """ + scores = [] + num = probabilities.shape[0] + predictions = probabilities >= treshold + assert predictions.shape == truth.shape + for i in range(num): + prediction = predictions[i] + truth_ = truth[i] + intersection = 2.0 * (truth_ * prediction).sum() + union = truth_.sum() + prediction.sum() + if truth_.sum() == 0 and prediction.sum() == 0: + scores.append(1.0) + else: + scores.append((intersection + eps) / union) + return np.mean(scores) + + +def jaccard_coef_metric( + probabilities: np.ndarray, truth: np.ndarray, treshold: float = 0.5, eps: float = 0 +) -> np.ndarray: + """ + Calculate Jaccard index for data batch. + Params: + probobilities: model outputs after activation function. + truth: truth values. + threshold: threshold for probabilities. + eps: additive to refine the estimate. + Returns: jaccard score aka iou." + """ + scores = [] + num = probabilities.shape[0] + predictions = probabilities >= treshold + assert predictions.shape == truth.shape + + for i in range(num): + prediction = predictions[i] + truth_ = truth[i] + intersection = (prediction * truth_).sum() + union = (prediction.sum() + truth_.sum()) - intersection + eps + if truth_.sum() == 0 and prediction.sum() == 0: + scores.append(1.0) + else: + scores.append((intersection + eps) / union) + return np.mean(scores) + + +def preprocess_mask_labels(mask: np.ndarray): + + mask_WT = mask.copy() + mask_WT[mask_WT == 1] = 1 + mask_WT[mask_WT == 2] = 1 + mask_WT[mask_WT == 4] = 1 + + mask_TC = mask.copy() + mask_TC[mask_TC == 1] = 1 + mask_TC[mask_TC == 2] = 0 + mask_TC[mask_TC == 4] = 1 + + mask_ET = mask.copy() + mask_ET[mask_ET == 1] = 0 + mask_ET[mask_ET == 2] = 0 + mask_ET[mask_ET == 4] = 1 + + mask = np.stack([mask_WT, mask_TC, mask_ET]) + mask = np.moveaxis(mask, (0, 1, 2, 3), (0, 3, 2, 1)) + + return mask + + +def load_img(file_path): + data = nib.load(file_path) + data = np.asarray(data.dataobj) + return data + + +def get_data_arr(predictions_path, ground_truth_path): + predictions = glob.glob(predictions_path + "/*") + ground_truth = glob.glob(ground_truth_path + "/*") + if not len(predictions) == len(ground_truth): + raise ValueError( + "Number of predictions should be the same of ground truth labels" + ) + gt_arr, prediction_arr = [], [] + for gt_path, prediction_path in zip(ground_truth, predictions): + gt = load_img(gt_path) + gt = preprocess_mask_labels(gt) + prediction = load_img(prediction_path) + prediction = preprocess_mask_labels(prediction) + gt_arr.append(gt) + prediction_arr.append(prediction) + gt_arr = np.concatenate(gt_arr) + prediction_arr = np.concatenate(prediction_arr) + return gt_arr, prediction_arr + + +def create_metrics_file(output_file, results): + with open(output_file, "w") as f: + yaml.dump(results, f) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--ground_truth", + type=str, + required=True, + help="Directory containing the ground truth data", + ) + parser.add_argument( + "--predictions", + type=str, + required=True, + help="Directory containing the predictions", + ) + parser.add_argument( + "--output_file", + "--output-file", + type=str, + required=True, + help="file to store metrics results as YAML", + ) + parser.add_argument( + "--parameters_file", + "--parameters-file", + type=str, + required=True, + help="File containing parameters for evaluation", + ) + args = parser.parse_args() + + with open(args.parameters_file, "r") as f: + params = yaml.full_load(f) + + gt_arr, pred_arr = get_data_arr(args.predictions, args.ground_truth) + + treshold = float(params["treshold"]) + eps = float(params["eps"]) + + dice_coef = dice_coef_metric(pred_arr, gt_arr, treshold, eps) + jaccard_coef = jaccard_coef_metric(pred_arr, gt_arr, treshold, eps) + + results = { + "dice_coef": str(dice_coef), + "jaccard_coef": str(jaccard_coef), + } + + print(results) + create_metrics_file(args.output_file, results) + + +if __name__ == "__main__": + main() diff --git a/brats/metrics/project/mlcube.py b/brats/metrics/project/mlcube.py new file mode 100644 index 0000000..986bdd7 --- /dev/null +++ b/brats/metrics/project/mlcube.py @@ -0,0 +1,43 @@ +"""MLCube handler file""" +import os +import typer +import subprocess + + +app = typer.Typer() + + +class EvaluateTask(object): + """Runs evaluation metrics given the predictions and label files + Args: + object ([type]): [description] + """ + + @staticmethod + def run( + ground_truth: str, predictions: str, parameters_file: str, output_file: str + ) -> None: + cmd = f"python3 metrics.py --ground_truth={ground_truth} --predictions={predictions} --parameters_file={parameters_file} --output_file={output_file}" + splitted_cmd = cmd.split() + + process = subprocess.Popen(splitted_cmd, cwd=".") + process.wait() + + +@app.command("evaluate") +def evaluate( + ground_truth: str = typer.Option(..., "--ground_truth"), + predictions: str = typer.Option(..., "--predictions"), + parameters_file: str = typer.Option(..., "--parameters_file"), + output_path: str = typer.Option(..., "--output_path"), +): + EvaluateTask.run(ground_truth, predictions, parameters_file, output_path) + + +@app.command("test") +def test(): + pass + + +if __name__ == "__main__": + app() diff --git a/brats/metrics/project/requirements.txt b/brats/metrics/project/requirements.txt new file mode 100644 index 0000000..0f4b422 --- /dev/null +++ b/brats/metrics/project/requirements.txt @@ -0,0 +1,4 @@ +PyYAML +typer +numpy +nibabel \ No newline at end of file diff --git a/brats/.gitignore b/brats/model/.gitignore similarity index 100% rename from brats/.gitignore rename to brats/model/.gitignore diff --git a/brats/README.md b/brats/model/README.md similarity index 74% rename from brats/README.md rename to brats/model/README.md index aa1211b..7feb48b 100644 --- a/brats/README.md +++ b/brats/model/README.md @@ -1,4 +1,4 @@ -# BraTS Challenge 2020 - MLCube integration +# BraTS Challenge 2020 - MLCube integration - Model Original implementation: ["BraTS Instructions Repo"](https://github.com/BraTS/Instructions) @@ -15,7 +15,7 @@ virtualenv -p python3 ./env && source ./env/bin/activate && pip install mlcube-d # Fetch the boston housing example from GitHub git clone https://github.com/mlcommons/mlcube_examples && cd ./mlcube_examples git fetch origin pull/39/head:feature/brats && git checkout feature/brats -cd ./brats +cd ./brats/model/mlcube ``` ## Important files @@ -23,18 +23,20 @@ cd ./brats These are the most important files on this project: ```bash -├── Dockerfile_CPU # Docker file with instructions to create the image for the CPU version. -├── Dockerfile_GPU # Docker file with instructions to create the image for the GPU version. -├── mlcube.py # Python entrypoint used by MLCube, contains the logic for MLCube tasks. -├── mlcube_cpu.yaml # MLCube CPU configuration, defines the project, author, platform, docker and tasks. -├── mlcube_gpu.yaml # MLCube GPU configuration, here the difference is the target dockerfile. -├── requirements.txt # Python requirements needed to run the project inside Docker. -├── src -│ ├── my_logic.py # Python file that contains the main logic of the project. -│ └── utils -│ └── utilities.py # Python utilities file that stores useful functions. -└── workspace - └── parameters.yaml # File containing all extra parameters. +├── mlcube +│ ├── mlcube_cpu.yaml # MLCube CPU configuration, defines the project, author, platform, docker and tasks. +│ ├── mlcube_gpu.yaml # MLCube GPU configuration, here the difference is the target dockerfile. +│ └── workspace +│ └── parameters.yaml # File containing all extra parameters. +└── project + ├── Dockerfile_CPU # Docker file with instructions to create the image for the CPU version. + ├── Dockerfile_GPU # Docker file with instructions to create the image for the GPU version. + ├── mlcube.py # Python entrypoint used by MLCube, contains the logic for MLCube tasks. + ├── requirements.txt # Python requirements needed to run the project inside Docker. + └── src + ├── my_logic.py # Python file that contains the main logic of the project. + └── utils + └── utilities.py # Python utilities file that stores useful functions. ``` ## Project workflow @@ -48,11 +50,11 @@ You can change each file described above in order to add your own implementation ### Requirements file In this file (`requirements.txt`) you can add all the python dependencies needed for running your implementation, these dependencies will be installed during the creation of the docker image, this happens when you run the ```mlcube run ...``` command. + ### Dockerfile You can use both, CPU or GPU version for the dockerfile (`Dockerfile_CPU`, `Dockerfile_GPU`), also, you can add or modify any steps inside the file, this comes handy when you need to install some OS dependencies or even when you want to change the base docker image, inside the file you can find some information about the existing steps. - ### Parameters file This is a yaml file (`parameters.yaml`)that contains all extra parameters that aren't files or directories, for example, here you can place all the hyperparameters that you will use for training a model. This file will be passed as an **input parameter** in the MLCube tasks and then it will be read inside the MLCube container. @@ -72,14 +74,13 @@ In the existing implementation you will find 2 tasks: This task takes the following parameters: - * Input parameters: - * input_folder: folder path containing input data - * parameters_file: Extra parameters - * Output parameters: - * output_folder: folder path where output data will be stored - - This task takes the input data, "process it" and then save the output result in the output_folder, it also prints some information from the extra parameters. + * Input parameters: + * input_folder: folder path containing input data + * parameters_file: Extra parameters + * Output parameters: + * output_folder: folder path where output data will be stored + This task takes the input data, "process it" and then save the output result in the output_folder, it also prints some information from the extra parameters. ### MLCube python file @@ -92,6 +93,7 @@ The `my_logic.py` file contains the main logic of the project, you can modify th ### Utilities file In the `utilities.py` file you can add some functions that will be useful for your main implementation, in this case, the functions from the utilities file are used inside the main logic file. + ## Tasks execution ```bash @@ -99,13 +101,13 @@ In the `utilities.py` file you can add some functions that will be useful for yo mlcube run --mlcube=mlcube_cpu.yaml --task=example # Run main task with CPU support. -mlcube run --mlcube=mlcube_cpu.yaml --task=run +mlcube run --mlcube=mlcube_cpu.yaml --task=infer # Run example task with GPU support. mlcube run --mlcube=mlcube_gpu.yaml --task=example # Run main task with GPU support. -mlcube run --mlcube=mlcube_gpu.yaml --task=run +mlcube run --mlcube=mlcube_gpu.yaml --task=infer ``` We are targeting pull-type installation, so MLCube images should be available on Docker Hub. If not, try this: diff --git a/brats/mlcube/mlcube_cpu.yaml b/brats/model/mlcube/mlcube_cpu.yaml similarity index 93% rename from brats/mlcube/mlcube_cpu.yaml rename to brats/model/mlcube/mlcube_cpu.yaml index 00b932f..653b4a0 100644 --- a/brats/mlcube/mlcube_cpu.yaml +++ b/brats/model/mlcube/mlcube_cpu.yaml @@ -24,4 +24,4 @@ tasks: # Run implementation parameters: inputs: {data_path: data/, parameters_file: parameters.yaml} - outputs: {output_folder: data/results/} + outputs: {output_path: data/results/} diff --git a/brats/mlcube/mlcube_gpu.yaml b/brats/model/mlcube/mlcube_gpu.yaml similarity index 93% rename from brats/mlcube/mlcube_gpu.yaml rename to brats/model/mlcube/mlcube_gpu.yaml index eb18d0f..c03e5f5 100644 --- a/brats/mlcube/mlcube_gpu.yaml +++ b/brats/model/mlcube/mlcube_gpu.yaml @@ -24,4 +24,4 @@ tasks: # Run implementation parameters: inputs: {data_path: data/, parameters_file: parameters.yaml} - outputs: {output_folder: data/results/} + outputs: {output_path: data/results/} diff --git a/brats/mlcube/workspace/data/results/.dockerignore b/brats/model/mlcube/workspace/data/results/.dockerignore similarity index 100% rename from brats/mlcube/workspace/data/results/.dockerignore rename to brats/model/mlcube/workspace/data/results/.dockerignore diff --git a/brats/mlcube/workspace/data/results/.gitignore b/brats/model/mlcube/workspace/data/results/.gitignore similarity index 100% rename from brats/mlcube/workspace/data/results/.gitignore rename to brats/model/mlcube/workspace/data/results/.gitignore diff --git a/brats/mlcube/workspace/data/something_t1.nii.gz b/brats/model/mlcube/workspace/data/something_t1.nii.gz similarity index 100% rename from brats/mlcube/workspace/data/something_t1.nii.gz rename to brats/model/mlcube/workspace/data/something_t1.nii.gz diff --git a/brats/mlcube/workspace/parameters.yaml b/brats/model/mlcube/workspace/parameters.yaml similarity index 100% rename from brats/mlcube/workspace/parameters.yaml rename to brats/model/mlcube/workspace/parameters.yaml diff --git a/brats/model/project/Dockerfile_CPU b/brats/model/project/Dockerfile_CPU new file mode 100644 index 0000000..436cf7c --- /dev/null +++ b/brats/model/project/Dockerfile_CPU @@ -0,0 +1,22 @@ +# for a CPU app use this Dockerfile. +FROM python:3.8-buster + +# fill in your info here +LABEL author="chuck@norris.org" +LABEL application="your application name" +LABEL maintainer="chuck@norris.org" +LABEL version="0.0.1" +LABEL status="beta" + +# basic +RUN apt-get -y update && apt -y full-upgrade && apt-get -y install apt-utils wget git tar build-essential curl nano + +# install all python requirements +WORKDIR /app +COPY ./requirements.txt ./requirements.txt +RUN pip3 install -r requirements.txt + +# copy all files +COPY ./ ./ + +ENTRYPOINT [ "python3", "mlcube.py"] diff --git a/brats/project/Dockerfile_GPU b/brats/model/project/Dockerfile_GPU similarity index 100% rename from brats/project/Dockerfile_GPU rename to brats/model/project/Dockerfile_GPU diff --git a/brats/project/LICENSE b/brats/model/project/LICENSE similarity index 100% rename from brats/project/LICENSE rename to brats/model/project/LICENSE diff --git a/brats/project/mlcube.py b/brats/model/project/mlcube.py similarity index 81% rename from brats/project/mlcube.py rename to brats/model/project/mlcube.py index 8ab6cb5..ba20384 100644 --- a/brats/project/mlcube.py +++ b/brats/model/project/mlcube.py @@ -27,12 +27,12 @@ class InferTask(object): """Run task Class It defines the environment variables: data_path: Directory path to dataset - output_folder: Directory path to final results + output_path: Directory path to final results All other parameters are defined in parameters_file Then executes the run_code method inside my_logic script""" @staticmethod - def run(data_path: str, output_folder: str, parameters_file: str) -> None: + def run(data_path: str, output_path: str, parameters_file: str) -> None: # Load parameters from the paramters file with open(parameters_file, "r") as stream: @@ -40,7 +40,7 @@ def run(data_path: str, output_folder: str, parameters_file: str) -> None: application_name = parameters["APPLICATION_NAME"] application_version = parameters["APPLICATION_VERSION"] - run_code(data_path, output_folder, application_name, application_version) + run_code(data_path, output_path, application_name, application_version) @app.command("example") @@ -51,10 +51,10 @@ def example(parameters_file: str = typer.Option(..., "--parameters_file")): @app.command("infer") def infer( data_path: str = typer.Option(..., "--data_path"), - output_folder: str = typer.Option(..., "--output_folder"), + output_path: str = typer.Option(..., "--output_path"), parameters_file: str = typer.Option(..., "--parameters_file") ): - InferTask.run(data_path, output_folder, parameters_file) + InferTask.run(data_path, output_path, parameters_file) if __name__ == "__main__": diff --git a/brats/project/requirements.txt b/brats/model/project/requirements.txt similarity index 100% rename from brats/project/requirements.txt rename to brats/model/project/requirements.txt diff --git a/brats/project/src/__init__.py b/brats/model/project/src/__init__.py similarity index 100% rename from brats/project/src/__init__.py rename to brats/model/project/src/__init__.py diff --git a/brats/project/src/my_logic.py b/brats/model/project/src/my_logic.py similarity index 100% rename from brats/project/src/my_logic.py rename to brats/model/project/src/my_logic.py diff --git a/brats/project/src/utils/__init__.py b/brats/model/project/src/utils/__init__.py similarity index 100% rename from brats/project/src/utils/__init__.py rename to brats/model/project/src/utils/__init__.py diff --git a/brats/project/src/utils/utilities.py b/brats/model/project/src/utils/utilities.py similarity index 100% rename from brats/project/src/utils/utilities.py rename to brats/model/project/src/utils/utilities.py From bbbf85a6227d085f8657b37b75f1a6e6cfe50002 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Feb 2022 11:34:13 -0500 Subject: [PATCH 09/28] Add comments to metrics file --- brats/metrics/project/metrics.py | 33 +++++++++++++++++++++----------- brats/metrics/project/mlcube.py | 7 ++----- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/brats/metrics/project/metrics.py b/brats/metrics/project/metrics.py index 689ce8f..3555e2f 100644 --- a/brats/metrics/project/metrics.py +++ b/brats/metrics/project/metrics.py @@ -1,4 +1,4 @@ -"""Logic file""" +"""Metrics file""" import argparse import glob import yaml @@ -8,20 +8,21 @@ def dice_coef_metric( - probabilities: np.ndarray, truth: np.ndarray, treshold: float = 0.5, eps: float = 0 + predictions: np.ndarray, truth: np.ndarray, treshold: float = 0.5, eps: float = 0 ) -> np.ndarray: """ Calculate Dice score for data batch. Params: - probobilities: model outputs after activation function. + predictions: model outputs after activation function. truth: truth values. - threshold: threshold for probabilities. + threshold: threshold for predictions. eps: additive to refine the estimate. Returns: dice score aka f1. """ + scores = [] - num = probabilities.shape[0] - predictions = probabilities >= treshold + num = predictions.shape[0] + predictions = predictions >= treshold assert predictions.shape == truth.shape for i in range(num): prediction = predictions[i] @@ -36,20 +37,21 @@ def dice_coef_metric( def jaccard_coef_metric( - probabilities: np.ndarray, truth: np.ndarray, treshold: float = 0.5, eps: float = 0 + predictions: np.ndarray, truth: np.ndarray, treshold: float = 0.5, eps: float = 0 ) -> np.ndarray: """ Calculate Jaccard index for data batch. Params: - probobilities: model outputs after activation function. + predictions: model outputs after activation function. truth: truth values. - threshold: threshold for probabilities. + threshold: threshold for predictions. eps: additive to refine the estimate. Returns: jaccard score aka iou." """ + scores = [] - num = probabilities.shape[0] - predictions = probabilities >= treshold + num = predictions.shape[0] + predictions = predictions >= treshold assert predictions.shape == truth.shape for i in range(num): @@ -65,6 +67,7 @@ def jaccard_coef_metric( def preprocess_mask_labels(mask: np.ndarray): + """Preprocess the mask labels from a numpy array""" mask_WT = mask.copy() mask_WT[mask_WT == 1] = 1 @@ -88,12 +91,17 @@ def preprocess_mask_labels(mask: np.ndarray): def load_img(file_path): + """Reads segmentations image as a numpy array""" + data = nib.load(file_path) data = np.asarray(data.dataobj) return data def get_data_arr(predictions_path, ground_truth_path): + """Reads the content for the predictions and ground truth folders + and then returns the data in numpy array format""" + predictions = glob.glob(predictions_path + "/*") ground_truth = glob.glob(ground_truth_path + "/*") if not len(predictions) == len(ground_truth): @@ -114,11 +122,14 @@ def get_data_arr(predictions_path, ground_truth_path): def create_metrics_file(output_file, results): + """Writes metrics to an output yaml file""" with open(output_file, "w") as f: yaml.dump(results, f) def main(): + """Main function that recieves input parameters and calculate metrics""" + parser = argparse.ArgumentParser() parser.add_argument( "--ground_truth", diff --git a/brats/metrics/project/mlcube.py b/brats/metrics/project/mlcube.py index 986bdd7..353a768 100644 --- a/brats/metrics/project/mlcube.py +++ b/brats/metrics/project/mlcube.py @@ -7,11 +7,8 @@ app = typer.Typer() -class EvaluateTask(object): - """Runs evaluation metrics given the predictions and label files - Args: - object ([type]): [description] - """ +class EvaluateTask: + """Runs evaluation metrics given the predictions and ground truth files""" @staticmethod def run( From 02fe758d918242fdd5cd4da6baf156375e324e2c Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Feb 2022 11:39:51 -0500 Subject: [PATCH 10/28] Fix readme --- brats/metrics/README.md | 2 +- brats/model/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brats/metrics/README.md b/brats/metrics/README.md index 49aa0cd..8cb7a29 100644 --- a/brats/metrics/README.md +++ b/brats/metrics/README.md @@ -1,4 +1,4 @@ -# BraTS Challenge 2020 - MLCube integration - Metrics +# BraTS Challenge - MLCube integration - Metrics Original implementation: ["BraTS Instructions Repo"](https://github.com/BraTS/Instructions) diff --git a/brats/model/README.md b/brats/model/README.md index 7feb48b..42d0f21 100644 --- a/brats/model/README.md +++ b/brats/model/README.md @@ -1,4 +1,4 @@ -# BraTS Challenge 2020 - MLCube integration - Model +# BraTS Challenge - MLCube integration - Model Original implementation: ["BraTS Instructions Repo"](https://github.com/BraTS/Instructions) From 6cfe2dcf02e9a868553b9df688dc5c61b5c7d7af Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 25 Feb 2022 12:01:27 -0500 Subject: [PATCH 11/28] Add preprocess MLCube --- brats/metrics/mlcube/mlcube.yaml | 6 +- brats/metrics/project/metrics.py | 1 - brats/preprocessing/.gitignore | 2 + brats/preprocessing/README.md | 101 ++++++++++++++++++ brats/preprocessing/mlcube/mlcube.yaml | 22 ++++ .../workspace/data/BraTS_example_seg.nii.gz | Bin 0 -> 26095 bytes .../mlcube/workspace/parameters.yaml | 1 + brats/preprocessing/project/Dockerfile | 24 +++++ brats/preprocessing/project/mlcube.py | 44 ++++++++ brats/preprocessing/project/preprocess.py | 100 +++++++++++++++++ brats/preprocessing/project/requirements.txt | 5 + brats/preprocessing/project/run.sh | 15 +++ 12 files changed, 319 insertions(+), 2 deletions(-) create mode 100644 brats/preprocessing/.gitignore create mode 100644 brats/preprocessing/README.md create mode 100644 brats/preprocessing/mlcube/mlcube.yaml create mode 100644 brats/preprocessing/mlcube/workspace/data/BraTS_example_seg.nii.gz create mode 100644 brats/preprocessing/mlcube/workspace/parameters.yaml create mode 100644 brats/preprocessing/project/Dockerfile create mode 100644 brats/preprocessing/project/mlcube.py create mode 100644 brats/preprocessing/project/preprocess.py create mode 100644 brats/preprocessing/project/requirements.txt create mode 100644 brats/preprocessing/project/run.sh diff --git a/brats/metrics/mlcube/mlcube.yaml b/brats/metrics/mlcube/mlcube.yaml index 41c6fcc..05d6a9e 100644 --- a/brats/metrics/mlcube/mlcube.yaml +++ b/brats/metrics/mlcube/mlcube.yaml @@ -18,5 +18,9 @@ tasks: evaluate: # Executes a number of metrics specified by the params file parameters: - inputs: {predictions: data/predictions/, ground_truth: data/ground_truth/, parameters_file: parameters.yaml} + inputs: { + predictions: data/predictions/, + ground_truth: data/ground_truth/, + parameters_file: parameters.yaml + } outputs: {output_path: {type: "file", default: "results.yaml"}} diff --git a/brats/metrics/project/metrics.py b/brats/metrics/project/metrics.py index 3555e2f..e0b6e3b 100644 --- a/brats/metrics/project/metrics.py +++ b/brats/metrics/project/metrics.py @@ -2,7 +2,6 @@ import argparse import glob import yaml -from pkgutil import get_data import nibabel as nib import numpy as np diff --git a/brats/preprocessing/.gitignore b/brats/preprocessing/.gitignore new file mode 100644 index 0000000..b5ca5c9 --- /dev/null +++ b/brats/preprocessing/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +mlcube/workspace/results \ No newline at end of file diff --git a/brats/preprocessing/README.md b/brats/preprocessing/README.md new file mode 100644 index 0000000..01b930d --- /dev/null +++ b/brats/preprocessing/README.md @@ -0,0 +1,101 @@ +# BraTS Challenge - MLCube integration - preprocess + +Original implementation: ["BraTS Instructions Repo"](https://github.com/BraTS/Instructions) + +## Dataset + +Please refer to the [BraTS challenge page](http://braintumorsegmentation.org/) and follow the instructions in the data section. + +## Project setup + +```bash +# Create Python environment and install MLCube Docker runner +virtualenv -p python3 ./env && source ./env/bin/activate && pip install mlcube-docker + +# Fetch the boston housing example from GitHub +git clone https://github.com/mlcommons/mlcube_examples && cd ./mlcube_examples +git fetch origin pull/39/head:feature/brats && git checkout feature/brats +cd ./brats/preprocessing/mlcube +``` + +## Important files + +These are the most important files on this project: + +```bash + +├── mlcube +│ ├── mlcube.yaml # MLCube configuration file, it defines the project, author, platform, docker and tasks. +│ └── workspace +│ ├── data +│ │ └── BraTS_example_seg.nii.gz # Input data +│ ├── results +│ │ └── output.npy # Output processed data +│ ├── parameters.yaml +└── project + ├── Dockerfile # Docker file with instructions to create the image for the project. + ├── preprocess.py # Python file that contains the main logic of the project. + ├── mlcube.py # Python entrypoint used by MLCube, contains the logic for MLCube tasks. + └── requirements.txt # Python requirements needed to run the project inside Docker. + └── run.sh # Bash file containing logic to call preprocess.py script. +``` + +## How to modify this project + +You can change each file described above in order to add your own implementation. + +### Requirements file + +In this file (`requirements.txt`) you can add all the python dependencies needed for running your implementation, these dependencies will be installed during the creation of the docker image, this happens when you run the ```mlcube run ...``` command. + +### Dockerfile + +You can use both, CPU or GPU version for the dockerfile (`Dockerfile_CPU`, `Dockerfile_GPU`), also, you can add or modify any steps inside the file, this comes handy when you need to install some OS dependencies or even when you want to change the base docker image, inside the file you can find some information about the existing steps. + +### Parameters file + +This is a yaml file (`parameters.yaml`)that contains all extra parameters that aren't files or directories, for example, here you can place all the hyperparameters that you will use for training a model. This file will be passed as an **input parameter** in the MLCube tasks and then it will be read inside the MLCube container. + +### MLCube yaml file + +In this file (`mlcube.yaml`) you can find the instructions about the docker image and platform that will be used, information about the project (name, description, authors), and also the tasks defined for the project. + +In the existing implementation you will find 1 task: + +* evaluate: + + This task takes the following parameters: + + * Input parameters: + * predictions: Folder path containing predictions + * ground_truth: Folder path containing ground truth data + * parameters_file: Extra parameters + * Output parameters: + * output_path: File path where output preprocess will be stored + + This task takes the input predictions and ground truth data, perform the evaluation and then save the output result in the output_path. + +### MLCube python file + +The `mlcube.py` file is the handler file and entrypoint described in the dockerfile, here you can find all the logic related to how to process each MLCube task. If you want to add a new task first you must define it inside the `mlcube.yaml` file with its input and output parameters and then you need to add the logic to handle this new task inside the `mlcube.py` file. + +### Preprocess file + +The `preprocess.py` file contains the main logic of the project, you can modify this file and write your implementation here to perform the different preprocessing steps, this preprocess file is called from the `run.sh` file and there are other ways to link your implementation and shown in the [MLCube examples repo](https://github.com/mlcommons/mlcube_examples). + +### Run bash file + +The `run.sh` file is called from `mlcube.py` and it receives the arguments, here we can perform different steps to then call the `preprocess.py` script. + +## Tasks execution + +```bash +# Run preprocess task. +mlcube run --mlcube=mlcube_cpu.yaml --task=preprocess +``` + +We are targeting pull-type installation, so MLCube images should be available on Docker Hub. If not, try this: + +```Bash +mlcube run ... -Pdocker.build_strategy=always +``` diff --git a/brats/preprocessing/mlcube/mlcube.yaml b/brats/preprocessing/mlcube/mlcube.yaml new file mode 100644 index 0000000..007491a --- /dev/null +++ b/brats/preprocessing/mlcube/mlcube.yaml @@ -0,0 +1,22 @@ +name: MLCommons Brats preprocessing +description: MLCommons Brats integration for preprocessing +authors: + - {name: "MLCommons Best Practices Working Group"} + +platform: + accelerator_count: 0 + +docker: + # Image name. + image: mlcommons/brats_preprocessing:0.0.1 + # Docker build context relative to $MLCUBE_ROOT. Default is `build`. + build_context: "../project" + # Docker file name within docker build context, default is `Dockerfile`. + build_file: "Dockerfile" + +tasks: + preprocess: + # Run preprocessing + parameters: + inputs: {data_path: data/, parameters_file: parameters.yaml} + outputs: {output_path: results/} diff --git a/brats/preprocessing/mlcube/workspace/data/BraTS_example_seg.nii.gz b/brats/preprocessing/mlcube/workspace/data/BraTS_example_seg.nii.gz new file mode 100644 index 0000000000000000000000000000000000000000..40c2c4620b070d7df0b3b07d2849c267f130d739 GIT binary patch literal 26095 zcmeHvdsI_*wtqWg?G?41H5FT}Xzxs06+~MR5W=I5<6A-%Ld5W>Rfs%7pdmzv2fRAy z9c`gg6y*_8L5L(IQ3DAia;SI}5lKYyFoX~o3W0h{_$I6 zEm?DjEV88-1K}WUIDGq>tz|?T zD9BpX^2~TQ(eaI9_Wtuf=Mk7kU><>a1m+Q#M_?X-c?9MWm`7k9fq4Yx5qLES{0}RB z&8asqYfAQN(se(3HQ)L2TfV)P3%#~Hvim`#+qsCXbm1%g@=vhPG3Mnz>>fz9*F#y!1`ttzlx`1Dfma&(;#Yhj#?;b5fYrx}l`_ujw7QITryVd+Z__|d^ zUhbPIdHZ+o>7RJFe@Gh1!?QVy3U01v!sZ>P=g5F*vLWSL24P`RY3sl;^vkC;^2RFD zukX_A(0s06v41tx9dM*N;@wwQ9mjN>y>cwu%=;B6#TdvyR3$9$ZitsjZjP{U#EyGnSBjL{tft&1^u~$c1R<%uRR7ue9bv!?o3xJ zrg6#<{G!|^-yVtiT(d-xU;AhS;xkqwrO3caCo~J~H6xNf{6I~5l0ET#8JV&9?sX0va6g|d zUbGV`ga1?7Swj@YVF|n|>{nySc&XL*L3dwq{PuyMj>L842?0wW(kgxK@{jN2V*JkV zQuUtYLx->fAG)4h0WHs>MV7%zGk8w^^yp-lLb8&H((Cbi7Tx!%7p^FU2c%()w7?y6 z#3X+ONDe z;?thO+)Y!24pZo5F6^d#5mWRowB7sMRpR-hIH+i(tS%lqu*{x_G66>#6xu(2?61Pa zLMajc>g#pz3NbMEix^-}8%LLTzuA@gs)$$|ISp*>fLeo&FGgLtEcSf3j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|P*vB=ob{9s$s@ zVD%k{IB^NO*%jDqV*%RuInr|Qxs!nI2N`-!)V#~?t$d{1;qH*+9FmTx_{-2p^dW(2 zIKg>w(yBu#L4k_mNHHfi15pLM7pSOw6{qjk7Wy6yzb#J353(H;3^iO4euV2Zdn=P` z($2wTlNEC!a4l$*AQ|GP%L^70scewK_+`n5EU)0@H6Yv0(QDP8`7oy#27LH(iCuYL zLBc_69f#9db*)7n?y?iG&F&f0DFWlBA+WVuQc0w(NCO0Lzi3^rwc!dJTzJpS&fZv) z){*il8CP)u@mj=Ce!zdZROf8V11zblNdO>2S{^Sems!;gu11PF5a)Ab?Q1_!_|pdB zsnA5{Ve}Zpd?vnh zd`ONR2v~;bL$Jn)c5Be`ZozQVN+u2&>e#K_F+68f!_ohq0fny|2=c*9=i7Bty z1PI-@GB06$xwRKNSj>jqD5*9~${4<00#A5gBPe`BT6}1w@tDeBHasosZ^K$>$;8uZ;=3u#s?%Vt-ZiI2eib6J zi>-&lH6aMM0%sZkZAEY}H=^(_2FxB!FVeSM*qpCI6aZ3*y0rmlfmkQl(Uh2Qjk3Ve z6dOjFT5`>liLf|8J#IUsM?!tB=Hq|;gs$ID<+b)qJ(ce&ISNHnxtlM8HMZ8i{G(cb z^8^3>lb_wQn=1Fs(WZcZ|KrZzaUOwr1pdzmOcw@k{e|l;&+`ZiF!Qf@1m+Q#M_?X- zc?9MWm`7k9fq4Yx5tv6{9)WoT<`MY+9f3>M{!)h cfq4Yx5tv6{ZV@ None: + + env = os.environ.copy() + env.update({ + 'data_path': data_path, + 'parameters_file': parameters_file, + 'output_path': output_path + }) + + process = subprocess.Popen("./run.sh", cwd=".", env=env) + process.wait() + + +@app.command("preprocess") +def preprocess( + data_path: str = typer.Option(..., "--data_path"), + parameters_file: str = typer.Option(..., "--parameters_file"), + output_path: str = typer.Option(..., "--output_path"), +): + PreprocessTask.run(data_path, parameters_file, output_path) + + +@app.command("test") +def test(): + pass + + +if __name__ == "__main__": + app() diff --git a/brats/preprocessing/project/preprocess.py b/brats/preprocessing/project/preprocess.py new file mode 100644 index 0000000..08d017d --- /dev/null +++ b/brats/preprocessing/project/preprocess.py @@ -0,0 +1,100 @@ +"""Metrics file""" +import os +import argparse +import glob +import yaml +import numpy as np +import nibabel as nib +from tqdm import tqdm + + +def preprocess(image: np.ndarray): + """Preprocess the image labels from a numpy array""" + + image_WT = image.copy() + image_WT[image_WT == 1] = 1 + image_WT[image_WT == 2] = 1 + image_WT[image_WT == 4] = 1 + + image_TC = image.copy() + image_TC[image_TC == 1] = 1 + image_TC[image_TC == 2] = 0 + image_TC[image_TC == 4] = 1 + + image_ET = image.copy() + image_ET[image_ET == 1] = 0 + image_ET[image_ET == 2] = 0 + image_ET[image_ET == 4] = 1 + + image = np.stack([image_WT, image_TC, image_ET]) + image = np.moveaxis(image, (0, 1, 2, 3), (0, 3, 2, 1)) + + return image + + +def load_img(file_path): + """Reads segmentations image as a numpy array""" + + data = nib.load(file_path) + data = np.asarray(data.dataobj) + return data + + +def get_data_arr(data_path): + """Reads the content for the data path folder + and then returns the data in numpy array format""" + + image_path_list = glob.glob(data_path + "/*") + images_arr = [] + for image_path in image_path_list: + image = load_img(image_path) + image = preprocess(image) + images_arr.append(image) + images_arr = np.concatenate(images_arr) + return images_arr + + +def save_processed_data(output_path, output_filename, images_arr): + """Writes processed images to the target output path""" + output_file_path = os.path.join(output_path, output_filename) + with open(output_file_path, 'wb') as f: + np.save(f, images_arr) + print("File correctly saved!") + + +def main(): + """Main function that recieves input data and preprocess it""" + + parser = argparse.ArgumentParser() + parser.add_argument( + "--data_path", + "--data-path", + type=str, + required=True, + help="Directory containing input data", + ) + parser.add_argument( + "--output_path", + "--output-path", + type=str, + required=True, + help="Path where output data will be stored", + ) + parser.add_argument( + "--parameters_file", + "--parameters-file", + type=str, + required=True, + help="File containing parameters for processing", + ) + args = parser.parse_args() + + with open(args.parameters_file, "r") as f: + params = yaml.full_load(f) + + images_arr = get_data_arr(args.data_path) + save_processed_data(args.output_path, params["output_filename"], images_arr) + + +if __name__ == "__main__": + main() diff --git a/brats/preprocessing/project/requirements.txt b/brats/preprocessing/project/requirements.txt new file mode 100644 index 0000000..2f512cf --- /dev/null +++ b/brats/preprocessing/project/requirements.txt @@ -0,0 +1,5 @@ +PyYAML +typer +numpy +nibabel +tqdm \ No newline at end of file diff --git a/brats/preprocessing/project/run.sh b/brats/preprocessing/project/run.sh new file mode 100644 index 0000000..8647fe1 --- /dev/null +++ b/brats/preprocessing/project/run.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e + +: ${data_path:=${1:-}} +: ${parameters_file:=${2:-}} +: ${output_path:=${2:-}} + +ARGS="--data_path=$data_path" +ARGS+=" --parameters_file $parameters_file" +ARGS+=" --output_path $output_path" + +# Execute command and time it +echo Processing data. This may take a while... +time python3 preprocess.py ${ARGS} \ No newline at end of file From 8521cf0453a8d29ab6a637403ef90665d72a07e7 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Wed, 16 Mar 2022 18:09:17 -0500 Subject: [PATCH 12/28] Update preprocessing MLCube task --- brats/preprocessing/mlcube/mlcube.yaml | 4 ++-- brats/preprocessing/project/mlcube.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/brats/preprocessing/mlcube/mlcube.yaml b/brats/preprocessing/mlcube/mlcube.yaml index 007491a..b4111d6 100644 --- a/brats/preprocessing/mlcube/mlcube.yaml +++ b/brats/preprocessing/mlcube/mlcube.yaml @@ -15,8 +15,8 @@ docker: build_file: "Dockerfile" tasks: - preprocess: + prepare: # Run preprocessing parameters: - inputs: {data_path: data/, parameters_file: parameters.yaml} + inputs: {data_path: data/, labels_path: {type: file, default: labels.csv}, parameters_file: {type: file, default: parameters.yaml}} outputs: {output_path: results/} diff --git a/brats/preprocessing/project/mlcube.py b/brats/preprocessing/project/mlcube.py index e586819..150bf88 100644 --- a/brats/preprocessing/project/mlcube.py +++ b/brats/preprocessing/project/mlcube.py @@ -26,9 +26,10 @@ def run( process.wait() -@app.command("preprocess") -def preprocess( +@app.command("prepare") +def prepare( data_path: str = typer.Option(..., "--data_path"), + labels_path: str = typer.Option(..., "--labels_path"), parameters_file: str = typer.Option(..., "--parameters_file"), output_path: str = typer.Option(..., "--output_path"), ): From 37730f42d704f872045ec3a3d4c1edaca9ea3362 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Mar 2022 10:10:13 -0500 Subject: [PATCH 13/28] Update readme --- brats/README.md | 156 ++++++++++++++++++ .../mlcube/{mlcube_cpu.yaml => mlcube.yaml} | 2 +- brats/model/mlcube/mlcube_gpu.yaml | 27 --- .../project/{Dockerfile_CPU => Dockerfile} | 0 brats/model/project/Dockerfile_GPU | 27 --- 5 files changed, 157 insertions(+), 55 deletions(-) create mode 100644 brats/README.md rename brats/model/mlcube/{mlcube_cpu.yaml => mlcube.yaml} (95%) delete mode 100644 brats/model/mlcube/mlcube_gpu.yaml rename brats/model/project/{Dockerfile_CPU => Dockerfile} (100%) delete mode 100644 brats/model/project/Dockerfile_GPU diff --git a/brats/README.md b/brats/README.md new file mode 100644 index 0000000..63fd647 --- /dev/null +++ b/brats/README.md @@ -0,0 +1,156 @@ +# MedPerf - MLCube - BraTs Challange Integration + +## Project setup + +```bash +# Create Python environment and install MLCube Docker runner +virtualenv -p python3 ./env && source ./env/bin/activate && pip install mlcube-docker + +# Fetch the boston housing example from GitHub +git clone https://github.com/mlcommons/mlcube_examples && cd ./mlcube_examples +git fetch origin pull/39/head:feature/brats && git checkout feature/brats +cd ./brats/metrics/mlcube +``` + +## MedPerf API Server + +To run locally, clone this repo: + +```Bash +git clone https://github.com/mlcommons/medperf.git +``` + +Go to the `server` folder + +```Bash +cd server +``` + +Install all dependencies + +```Bash +pip install -r requirements.txt +``` + +Create .env file with your environment settings + +Sample .env.example is added to root. Rename `.env.example` to `.env` and modify with your env vars. + +```Bash +cp .env.example .env +``` + +Create tables and existing models + +```Bash +python manage.py migrate +``` + +Start the server + +```Bash +python manage.py runserver +``` + +API Server is running at `http://127.0.0.1:8000/` by default. You can view and experiment Medperf API at `http://127.0.0.1:8000/swagger` + +## Medperf CLI + +The Medperf CLI is a command-line-interface that provides tools for preparing datasets and executing benchmarks on such datasets. + +To install, clone this repo (If you already did skip this step): + +```Bash +git clone https://github.com/mlcommons/medperf.git +``` + +Go to the `cli` folder + +```Bash +cd cli +``` + +Install using pip + +```Bash +pip install -e . +``` + +## How to run + +The MedPerf CLI provides the following commands: + +- `login`: authenticates the CLI with the medperf backend server + +```Bash +medperf login +``` + +- `dataset ls`: Lists all registered datasets by the user + +```Bash +medperf dataset ls +``` + +- `dataset create`: Prepares a raw dataset for a specific benchmark + +```Bash +medperf dataset create -b -d -l +``` + +- `dataset submit`: Submits a prepared local dataset to the platform. + +```Bash +medperf dataset submit -d +``` + +- `dataset associate`: Associates a prepared dataset with a specific benchmark + +```Bash +medperf associate -b -d +``` + +- `run`: Alias for `result create`. Runs a specific model from a benchmark with a specified prepared dataset + +```Bash +medperf run -b -d -m +``` + +- `result ls`: Displays all results created by the user + +```Bash +medperf result ls +``` + + +- `result create`: Runs a specific model from a benchmark with a specified prepared dataset + +```Bash +medperf result create -b -d -m +``` + +- `result submit`: Submits already obtained results to the platform + +```Bash +medperf result submit -b -d -m +``` + +- `mlcube ls`: Lists all mlcubes created by the user. Lists all mlcubes if `--all` is passed + +```Bash +medperf mlcube ls [--all] +``` + +- `mlcube submit`: Submits a new mlcube to the platform + +```Bash +medperf mlcube submit +``` + +- `mlcube associate`: Associates an MLCube to a benchmark + +```Bash +medperf mlcube associate -b -m +``` + +The CLI runs MLCubes behind the scene. This cubes require a container engine like docker, and so that engine must be running before running commands like `prepare` and `execute` diff --git a/brats/model/mlcube/mlcube_cpu.yaml b/brats/model/mlcube/mlcube.yaml similarity index 95% rename from brats/model/mlcube/mlcube_cpu.yaml rename to brats/model/mlcube/mlcube.yaml index 653b4a0..643cfbb 100644 --- a/brats/model/mlcube/mlcube_cpu.yaml +++ b/brats/model/mlcube/mlcube.yaml @@ -12,7 +12,7 @@ docker: # Docker build context relative to $MLCUBE_ROOT. Default is `build`. build_context: "../project" # Docker file name within docker build context, default is `Dockerfile`. - build_file: "Dockerfile_CPU" + build_file: "Dockerfile" tasks: example: diff --git a/brats/model/mlcube/mlcube_gpu.yaml b/brats/model/mlcube/mlcube_gpu.yaml deleted file mode 100644 index c03e5f5..0000000 --- a/brats/model/mlcube/mlcube_gpu.yaml +++ /dev/null @@ -1,27 +0,0 @@ -name: MLCommons Brats -description: MLCommons Brats integration -authors: - - {name: "MLCommons Best Practices Working Group"} - -platform: - accelerator_count: 0 - -docker: - # Image name. - image: mlcommons/brats_gpu:0.0.1 - # Docker build context relative to $MLCUBE_ROOT. Default is `build`. - build_context: "../project" - # Docker file name within docker build context, default is `Dockerfile`. - build_file: "Dockerfile_GPU" - -tasks: - example: - # Run implementation - parameters: - inputs: {parameters_file: {type: file, default: parameters.yaml}} - - infer: - # Run implementation - parameters: - inputs: {data_path: data/, parameters_file: parameters.yaml} - outputs: {output_path: data/results/} diff --git a/brats/model/project/Dockerfile_CPU b/brats/model/project/Dockerfile similarity index 100% rename from brats/model/project/Dockerfile_CPU rename to brats/model/project/Dockerfile diff --git a/brats/model/project/Dockerfile_GPU b/brats/model/project/Dockerfile_GPU deleted file mode 100644 index bc2c233..0000000 --- a/brats/model/project/Dockerfile_GPU +++ /dev/null @@ -1,27 +0,0 @@ -# for a GPU app use this Dockerfile. -FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04 - -# fill in your info here -LABEL author="chuck@norris.org" -LABEL application="your application name" -LABEL maintainer="chuck@norris.org" -# specify version here, if possible use semantic versioning -LABEL version="0.0.1" -LABEL status="beta" - -# basic -RUN apt-get -y update && apt -y full-upgrade && apt-get -y install apt-utils wget git tar build-essential curl nano - -# install python 3.6.9 -RUN apt-get update -y && apt-get install -y python3-pip python3-dev - -# install all python requirements -WORKDIR /app -COPY ./requirements.txt ./requirements.txt -RUN pip3 install -r requirements.txt - -# copy all files -COPY ./ ./ -RUN pip3 install -U python-dotenv - -ENTRYPOINT [ "python3", "mlcube.py"] From aa4dfda0179ee2d3089d9e750266846f08c2220a Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Mar 2022 10:26:49 -0500 Subject: [PATCH 14/28] Fix preprocessing mlcube.yaml file --- brats/preprocessing/mlcube/mlcube.yaml | 4 ++++ brats/preprocessing/project/mlcube.py | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/brats/preprocessing/mlcube/mlcube.yaml b/brats/preprocessing/mlcube/mlcube.yaml index b4111d6..851fb27 100644 --- a/brats/preprocessing/mlcube/mlcube.yaml +++ b/brats/preprocessing/mlcube/mlcube.yaml @@ -20,3 +20,7 @@ tasks: parameters: inputs: {data_path: data/, labels_path: {type: file, default: labels.csv}, parameters_file: {type: file, default: parameters.yaml}} outputs: {output_path: results/} + +sanity_check: + parameters: + inputs: {data_path: data/, parameters_file: parameters.yaml} \ No newline at end of file diff --git a/brats/preprocessing/project/mlcube.py b/brats/preprocessing/project/mlcube.py index 150bf88..4255ec6 100644 --- a/brats/preprocessing/project/mlcube.py +++ b/brats/preprocessing/project/mlcube.py @@ -36,8 +36,11 @@ def prepare( PreprocessTask.run(data_path, parameters_file, output_path) -@app.command("test") -def test(): +@app.command("sanity_check") +def sanity_check( + data_path: str = typer.Option(..., "--data_path"), + parameters_file: str = typer.Option(..., "--parameters_file"), +): pass From 8376c35676e1194b63cc3b7c5305c565c24a4525 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Mar 2022 10:34:28 -0500 Subject: [PATCH 15/28] Fix preprocessing sanity check --- brats/preprocessing/mlcube/mlcube.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brats/preprocessing/mlcube/mlcube.yaml b/brats/preprocessing/mlcube/mlcube.yaml index 851fb27..5b2a883 100644 --- a/brats/preprocessing/mlcube/mlcube.yaml +++ b/brats/preprocessing/mlcube/mlcube.yaml @@ -21,6 +21,6 @@ tasks: inputs: {data_path: data/, labels_path: {type: file, default: labels.csv}, parameters_file: {type: file, default: parameters.yaml}} outputs: {output_path: results/} -sanity_check: - parameters: - inputs: {data_path: data/, parameters_file: parameters.yaml} \ No newline at end of file + sanity_check: + parameters: + inputs: {data_path: data/, parameters_file: {type: file, default: parameters.yaml}} \ No newline at end of file From 5de23b9428fed9a600c19f7cb13031ff8dc131db Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Mar 2022 10:47:49 -0500 Subject: [PATCH 16/28] Add missing task for preprocessing MLCube --- brats/preprocessing/mlcube/mlcube.yaml | 7 ++++++- brats/preprocessing/project/mlcube.py | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/brats/preprocessing/mlcube/mlcube.yaml b/brats/preprocessing/mlcube/mlcube.yaml index 5b2a883..35cda09 100644 --- a/brats/preprocessing/mlcube/mlcube.yaml +++ b/brats/preprocessing/mlcube/mlcube.yaml @@ -23,4 +23,9 @@ tasks: sanity_check: parameters: - inputs: {data_path: data/, parameters_file: {type: file, default: parameters.yaml}} \ No newline at end of file + inputs: {data_path: data/, parameters_file: {type: file, default: parameters.yaml}} + + statistics: + parameters: + inputs: {data_path: data/, parameters_file: {type: file, default: parameters.yaml}} + outputs: {output_path: {type: file, default: statistics.yaml}} \ No newline at end of file diff --git a/brats/preprocessing/project/mlcube.py b/brats/preprocessing/project/mlcube.py index 4255ec6..c0c3874 100644 --- a/brats/preprocessing/project/mlcube.py +++ b/brats/preprocessing/project/mlcube.py @@ -1,6 +1,7 @@ """MLCube handler file""" import os import typer +import yaml import subprocess @@ -43,6 +44,18 @@ def sanity_check( ): pass +@app.command("statistics") +def statistics( + data_path: str = typer.Option(..., "--data_path"), + parameters_file: str = typer.Option(..., "--parameters_file"), + output_path: str = typer.Option(..., "--output_path") +): + stats = { + "stat": 1 + } + with open(output_path, "w") as f: + yaml.dump(stats, f) + if __name__ == "__main__": app() From bce60edd780755e6ff263a8497450eac3b87f411 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Mar 2022 10:54:38 -0500 Subject: [PATCH 17/28] Add model MLCube --- brats/model/project/mlcube.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brats/model/project/mlcube.py b/brats/model/project/mlcube.py index ba20384..0b9a919 100644 --- a/brats/model/project/mlcube.py +++ b/brats/model/project/mlcube.py @@ -1,5 +1,6 @@ """MLCube handler file""" import os +import shutil import typer import yaml from src.my_logic import run_code @@ -54,7 +55,8 @@ def infer( output_path: str = typer.Option(..., "--output_path"), parameters_file: str = typer.Option(..., "--parameters_file") ): - InferTask.run(data_path, output_path, parameters_file) + filename = "BraTS_example_seg.nii.gz" + shutil.copyfile(data_path+filename, output_path+filename) if __name__ == "__main__": From f47949bacd6c7b29e0122fa6117c1686a7a4ed7c Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Mar 2022 11:05:05 -0500 Subject: [PATCH 18/28] Fix metrics MLCube --- brats/metrics/mlcube/mlcube.yaml | 4 ++-- brats/metrics/project/mlcube.py | 9 +++++++-- brats/model/mlcube/mlcube.yaml | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/brats/metrics/mlcube/mlcube.yaml b/brats/metrics/mlcube/mlcube.yaml index 05d6a9e..e6112af 100644 --- a/brats/metrics/mlcube/mlcube.yaml +++ b/brats/metrics/mlcube/mlcube.yaml @@ -20,7 +20,7 @@ tasks: parameters: inputs: { predictions: data/predictions/, - ground_truth: data/ground_truth/, - parameters_file: parameters.yaml + labels: data/ground_truth/, + parameters_file: {type: file, default: parameters.yaml} } outputs: {output_path: {type: "file", default: "results.yaml"}} diff --git a/brats/metrics/project/mlcube.py b/brats/metrics/project/mlcube.py index 353a768..b6bb91f 100644 --- a/brats/metrics/project/mlcube.py +++ b/brats/metrics/project/mlcube.py @@ -1,5 +1,6 @@ """MLCube handler file""" import os +import yaml import typer import subprocess @@ -23,12 +24,16 @@ def run( @app.command("evaluate") def evaluate( - ground_truth: str = typer.Option(..., "--ground_truth"), + labels: str = typer.Option(..., "--labels"), predictions: str = typer.Option(..., "--predictions"), parameters_file: str = typer.Option(..., "--parameters_file"), output_path: str = typer.Option(..., "--output_path"), ): - EvaluateTask.run(ground_truth, predictions, parameters_file, output_path) + stats = { + "stat": 1 + } + with open(output_path, "w") as f: + yaml.dump(stats, f) @app.command("test") diff --git a/brats/model/mlcube/mlcube.yaml b/brats/model/mlcube/mlcube.yaml index 643cfbb..51ce023 100644 --- a/brats/model/mlcube/mlcube.yaml +++ b/brats/model/mlcube/mlcube.yaml @@ -23,5 +23,5 @@ tasks: infer: # Run implementation parameters: - inputs: {data_path: data/, parameters_file: parameters.yaml} + inputs: {data_path: data/, parameters_file: {type: file, default: parameters.yaml}} outputs: {output_path: data/results/} From 7d13bc5fc174dfdfeab19a30a0dfe2e103f64239 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Mar 2022 11:12:42 -0500 Subject: [PATCH 19/28] Fix model MLCube --- brats/model/mlcube/mlcube.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brats/model/mlcube/mlcube.yaml b/brats/model/mlcube/mlcube.yaml index 51ce023..af9c07d 100644 --- a/brats/model/mlcube/mlcube.yaml +++ b/brats/model/mlcube/mlcube.yaml @@ -24,4 +24,4 @@ tasks: # Run implementation parameters: inputs: {data_path: data/, parameters_file: {type: file, default: parameters.yaml}} - outputs: {output_path: data/results/} + outputs: {output_path: output/} From 9ecfc19b4e1216da203e5b7a4f6c486665cd6590 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 18 Mar 2022 15:08:54 -0500 Subject: [PATCH 20/28] Fix model paths --- brats/model/project/mlcube.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brats/model/project/mlcube.py b/brats/model/project/mlcube.py index 0b9a919..fdd2a29 100644 --- a/brats/model/project/mlcube.py +++ b/brats/model/project/mlcube.py @@ -56,7 +56,8 @@ def infer( parameters_file: str = typer.Option(..., "--parameters_file") ): filename = "BraTS_example_seg.nii.gz" - shutil.copyfile(data_path+filename, output_path+filename) + shutil.copyfile(os.path.join(data_path, filename), os.path.join(output_path, filename)) + print("Done!") if __name__ == "__main__": From 04343213e5ea305fb4378fe5da544e3fafca8d18 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Tue, 22 Mar 2022 18:00:42 -0500 Subject: [PATCH 21/28] Fix preprocessing logic --- brats/preprocessing/mlcube/mlcube.yaml | 2 +- brats/preprocessing/project/mlcube.py | 39 +++++++++++++++++---- brats/preprocessing/project/sanity_check.py | 28 +++++++++++++++ brats/preprocessing/project/statistics.py | 39 +++++++++++++++++++++ 4 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 brats/preprocessing/project/sanity_check.py create mode 100644 brats/preprocessing/project/statistics.py diff --git a/brats/preprocessing/mlcube/mlcube.yaml b/brats/preprocessing/mlcube/mlcube.yaml index 35cda09..f29de99 100644 --- a/brats/preprocessing/mlcube/mlcube.yaml +++ b/brats/preprocessing/mlcube/mlcube.yaml @@ -28,4 +28,4 @@ tasks: statistics: parameters: inputs: {data_path: data/, parameters_file: {type: file, default: parameters.yaml}} - outputs: {output_path: {type: file, default: statistics.yaml}} \ No newline at end of file + outputs: {output_path: {type: file, default: statistics.yaml}} diff --git a/brats/preprocessing/project/mlcube.py b/brats/preprocessing/project/mlcube.py index c0c3874..717c2eb 100644 --- a/brats/preprocessing/project/mlcube.py +++ b/brats/preprocessing/project/mlcube.py @@ -9,7 +9,7 @@ class PreprocessTask: - """Runs preprocessing given the input data path""" + """Run preprocessing given the input data path""" @staticmethod def run( @@ -26,6 +26,35 @@ def run( process = subprocess.Popen("./run.sh", cwd=".", env=env) process.wait() +class SanityCheckTask: + """Run sanity check""" + + @staticmethod + def run( + data_path: str, parameters_file: str + ) -> None: + + cmd = f"python3 sanity_check.py --data_path={data_path}" + splitted_cmd = cmd.split() + + process = subprocess.Popen(splitted_cmd, cwd=".") + process.wait() + + +class StatisticsTask: + """Run statistics""" + + @staticmethod + def run( + data_path: str, parameters_file: str, output_path: str + ) -> None: + + cmd = f"python3 statistics.py --data_path={data_path} --out_file={output_path}" + splitted_cmd = cmd.split() + + process = subprocess.Popen(splitted_cmd, cwd=".") + process.wait() + @app.command("prepare") def prepare( @@ -42,7 +71,7 @@ def sanity_check( data_path: str = typer.Option(..., "--data_path"), parameters_file: str = typer.Option(..., "--parameters_file"), ): - pass + SanityCheckTask.run(data_path, parameters_file) @app.command("statistics") def statistics( @@ -50,11 +79,7 @@ def statistics( parameters_file: str = typer.Option(..., "--parameters_file"), output_path: str = typer.Option(..., "--output_path") ): - stats = { - "stat": 1 - } - with open(output_path, "w") as f: - yaml.dump(stats, f) + StatisticsTask.run(data_path, parameters_file, output_path) if __name__ == "__main__": diff --git a/brats/preprocessing/project/sanity_check.py b/brats/preprocessing/project/sanity_check.py new file mode 100644 index 0000000..4766663 --- /dev/null +++ b/brats/preprocessing/project/sanity_check.py @@ -0,0 +1,28 @@ +"""Sanity check logic""" +import os +import argparse + + +def sanity_check(data): + """Runs a few checks to ensure data quality and integrity + Args: + names_df (pd.DataFrame): DataFrame containing transformed data. + """ + # Here you must add all the checks you consider important regarding the + # state of the data + assert len(data) > 0 + + +if __name__ == "__main__": + parser = argparse.ArgumentParser("Medperf Model Sanity Check Example") + parser.add_argument( + "--data_path", + dest="data", + type=str, + help="directory containing the prepared data", + ) + + args = parser.parse_args() + + data = os.listdir(args.data) + sanity_check(data) diff --git a/brats/preprocessing/project/statistics.py b/brats/preprocessing/project/statistics.py new file mode 100644 index 0000000..daaf7e2 --- /dev/null +++ b/brats/preprocessing/project/statistics.py @@ -0,0 +1,39 @@ +import os +import yaml +import argparse + + +def get_statistics(data_path): + """Computes statistics about the data. This statistics are uploaded + to the Medperf platform under the data owner's approval. Include + every statistic you consider useful for determining the nature of the + data, but keep in mind that we want to keep the data as private as + possible. + """ + + len_data = len(os.listdir(data_path)) + + stats = { + "data length": len_data + } + + return stats + + +if __name__ == "__main__": + parser = argparse.ArgumentParser("MedPerf Statistics Example") + parser.add_argument( + "--data_path", + type=str, + help="directory containing the prepared data", + ) + parser.add_argument( + "--out_file", dest="out_file", type=str, help="file to store statistics" + ) + + args = parser.parse_args() + + stats = get_statistics(args.data_path) + + with open(args.out_file, "w") as f: + yaml.dump(stats, f) From 10bbfe62af306fbb38e69b2133fc0161e5d9000a Mon Sep 17 00:00:00 2001 From: David Jurado Date: Thu, 24 Mar 2022 20:06:09 -0500 Subject: [PATCH 22/28] Fix model logic --- brats/model/project/mlcube.py | 6 +----- brats/model/project/src/my_logic.py | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/brats/model/project/mlcube.py b/brats/model/project/mlcube.py index fdd2a29..51648df 100644 --- a/brats/model/project/mlcube.py +++ b/brats/model/project/mlcube.py @@ -1,6 +1,4 @@ """MLCube handler file""" -import os -import shutil import typer import yaml from src.my_logic import run_code @@ -55,9 +53,7 @@ def infer( output_path: str = typer.Option(..., "--output_path"), parameters_file: str = typer.Option(..., "--parameters_file") ): - filename = "BraTS_example_seg.nii.gz" - shutil.copyfile(os.path.join(data_path, filename), os.path.join(output_path, filename)) - print("Done!") + InferTask.run(data_path, output_path, parameters_file) if __name__ == "__main__": diff --git a/brats/model/project/src/my_logic.py b/brats/model/project/src/my_logic.py index c237d07..cfc8d3b 100644 --- a/brats/model/project/src/my_logic.py +++ b/brats/model/project/src/my_logic.py @@ -6,8 +6,8 @@ def logic_wrapper(input_folder, output_folder): """Edit your logic here""" - input_file = os.path.normpath(input_folder + "/something_t1.nii.gz") - output_file = os.path.normpath(output_folder + "/something_seg.nii.gz") + input_file = os.path.normpath(input_folder + "/BraTS_example_seg.nii.gz") + output_file = os.path.normpath(output_folder + "/BraTS_example_seg.nii.gz") # copy paste your logic here print("wrapper: Here you can place your own logic") From cc0fc4059833b49242c1a4054e0627b5c3bcf7c0 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 25 Mar 2022 09:01:34 -0500 Subject: [PATCH 23/28] Fix model files --- .../workspace/data/BraTS_example_seg.nii.gz | Bin 0 -> 26095 bytes .../mlcube/workspace/data/something_t1.nii.gz | 1 - .../{data/results => output}/.dockerignore | 0 .../{data/results => output}/.gitignore | 0 4 files changed, 1 deletion(-) create mode 100644 brats/model/mlcube/workspace/data/BraTS_example_seg.nii.gz delete mode 100644 brats/model/mlcube/workspace/data/something_t1.nii.gz rename brats/model/mlcube/workspace/{data/results => output}/.dockerignore (100%) rename brats/model/mlcube/workspace/{data/results => output}/.gitignore (100%) diff --git a/brats/model/mlcube/workspace/data/BraTS_example_seg.nii.gz b/brats/model/mlcube/workspace/data/BraTS_example_seg.nii.gz new file mode 100644 index 0000000000000000000000000000000000000000..40c2c4620b070d7df0b3b07d2849c267f130d739 GIT binary patch literal 26095 zcmeHvdsI_*wtqWg?G?41H5FT}Xzxs06+~MR5W=I5<6A-%Ld5W>Rfs%7pdmzv2fRAy z9c`gg6y*_8L5L(IQ3DAia;SI}5lKYyFoX~o3W0h{_$I6 zEm?DjEV88-1K}WUIDGq>tz|?T zD9BpX^2~TQ(eaI9_Wtuf=Mk7kU><>a1m+Q#M_?X-c?9MWm`7k9fq4Yx5qLES{0}RB z&8asqYfAQN(se(3HQ)L2TfV)P3%#~Hvim`#+qsCXbm1%g@=vhPG3Mnz>>fz9*F#y!1`ttzlx`1Dfma&(;#Yhj#?;b5fYrx}l`_ujw7QITryVd+Z__|d^ zUhbPIdHZ+o>7RJFe@Gh1!?QVy3U01v!sZ>P=g5F*vLWSL24P`RY3sl;^vkC;^2RFD zukX_A(0s06v41tx9dM*N;@wwQ9mjN>y>cwu%=;B6#TdvyR3$9$ZitsjZjP{U#EyGnSBjL{tft&1^u~$c1R<%uRR7ue9bv!?o3xJ zrg6#<{G!|^-yVtiT(d-xU;AhS;xkqwrO3caCo~J~H6xNf{6I~5l0ET#8JV&9?sX0va6g|d zUbGV`ga1?7Swj@YVF|n|>{nySc&XL*L3dwq{PuyMj>L842?0wW(kgxK@{jN2V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tar.gz | Bin 0 -> 9446 bytes brats/metrics/project/mlcube.py | 6 +----- 2 files changed, 1 insertion(+), 5 deletions(-) create mode 100644 brats/data/tmp.tar.gz diff --git a/brats/data/tmp.tar.gz b/brats/data/tmp.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..a3dd006a3a301573861692856d5c68becfed71c7 GIT binary patch literal 9446 zcmVh;U5&nK*oEay*6@kKK}zn79R-^0=@;O4*&yMVc`8+mX=|405@Z8%PalE1lzZ=|6T(Zuz&?DU;ztQzycPqfCVgI z0sq_ZPjt-sbMGS87adfkYJN4ZxBl){Hn3<_gy=~G>{9s7a^Ae&d>aZlNxS}+{r$<- z>hPV^))8Z94IzN^&isv_F9%{>%G%OAN=WK?F-NLPl>}hSO#-x-rdbK(75OP92qc0(&4_V!7oWHZtY)*m>sR2 zJz9}^d!K5L>PzkF!|MQ%e_U1gM{_fPe*=xu$O|62ZBJgE;!UoBZHyAi_w;YGA*1>| z+5j^8MmJ}L3xaJRdmLWn7;LC2J--!ktf;5vaLtza8sgZr7+jLso$%ctTk{&Xsk92O zaVxDNS=~x2RzTlw#;mO7=rWtQ2g7AkNw>*@3R-W2o^uDhWvqaIW7tQ$`P;omUN z89P&zvMIED7`rt4#dmShU#gbNa%-P?IGh#`)h?SKb6AP=UB&z4dj|IB^U8M*cqn)< zY?R?XOr2PhTZ@mmi*k_O+2_%AzKytpWU~3Xr~j$f)g2%j^#?R1l`$(h(^4q{#(#K3 z1roHuVaPVHtu?||qu`&es9=L)EGx9eZGKES8%9}wGKtW^x|voH@3RuY9=!-2Fq2#m zucHeTvUQW&_upagJ(J&;aasH=bp%qIoUfy&;+uKa>S19ow!bw@4p-%uGMC*`ussQ z()R*8S?g9hcnsD5sdMZyU{wY+q6Cy1p>cAiMkcys!ZkFwR*OBb^s#$AZ*?))FAl9q z3D`3~QrJh*$u@NDlMj;Pz7=_3cB^J=7+DU48#S7eula5UR3c5GZwggyvhlR7h$xe* zHh7s99YZj?m7a(|sg|n&2_x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8qQLK%#oX$9AWv1Nx<=j|!hRmmiHcZo~c9@RZvk~MNzQA1GTe1Jo-CAEqQf&w~x zYt4s_Y8Q&TocCteK7Xm?<`@>PLvEaz7r(jG+=Ch@WPmVovIW_=yZ?N10)=Fv#Jh?&gu%Rke9||M`I9 s^WQKICkWWEWvk;Ku$heT^SNIV#DY33U;ztQ!2clpGm&Eb-~e_204OJ^M*si- literal 0 HcmV?d00001 diff --git a/brats/metrics/project/mlcube.py b/brats/metrics/project/mlcube.py index b6bb91f..be570b7 100644 --- a/brats/metrics/project/mlcube.py +++ b/brats/metrics/project/mlcube.py @@ -29,11 +29,7 @@ def evaluate( parameters_file: str = typer.Option(..., "--parameters_file"), output_path: str = typer.Option(..., "--output_path"), ): - stats = { - "stat": 1 - } - with open(output_path, "w") as f: - yaml.dump(stats, f) + EvaluateTask.run(labels, predictions, parameters_file, output_path) @app.command("test") From 128c69193b183dcbe4997b0b6df620b796beff34 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 25 Mar 2022 18:26:32 -0500 Subject: [PATCH 25/28] Add preprocessing output as model input --- brats/preprocessing/project/mlcube.py | 13 +++++-------- brats/preprocessing/project/preprocess.py | 4 ++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/brats/preprocessing/project/mlcube.py b/brats/preprocessing/project/mlcube.py index 717c2eb..d8f9ec6 100644 --- a/brats/preprocessing/project/mlcube.py +++ b/brats/preprocessing/project/mlcube.py @@ -16,14 +16,11 @@ def run( data_path: str, parameters_file: str, output_path: str ) -> None: - env = os.environ.copy() - env.update({ - 'data_path': data_path, - 'parameters_file': parameters_file, - 'output_path': output_path - }) - - process = subprocess.Popen("./run.sh", cwd=".", env=env) + cmd = f"python3 preprocess.py --data_path={data_path} \ + --parameters_file {parameters_file} --output_path {output_path}" + splitted_cmd = cmd.split() + + process = subprocess.Popen(splitted_cmd, cwd=".") process.wait() class SanityCheckTask: diff --git a/brats/preprocessing/project/preprocess.py b/brats/preprocessing/project/preprocess.py index 08d017d..56d5bf3 100644 --- a/brats/preprocessing/project/preprocess.py +++ b/brats/preprocessing/project/preprocess.py @@ -5,6 +5,7 @@ import yaml import numpy as np import nibabel as nib +from shutil import copyfile from tqdm import tqdm @@ -95,6 +96,9 @@ def main(): images_arr = get_data_arr(args.data_path) save_processed_data(args.output_path, params["output_filename"], images_arr) + input_file = os.path.normpath(args.data_path + "/BraTS_example_seg.nii.gz") + output_file = os.path.normpath(args.output_path + "/BraTS_example_seg.nii.gz") + copyfile(input_file, output_file) if __name__ == "__main__": main() From 7fc23871f48ec84c80bd946eb284aede4dbd6d57 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 8 Apr 2022 10:11:35 -0500 Subject: [PATCH 26/28] Update Readme --- brats/README.md | 14 ++++++++++++++ brats/model/README.md | 24 ++++++++---------------- brats/model/mlcube/mlcube.yaml | 2 +- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/brats/README.md b/brats/README.md index 63fd647..d4bd8e2 100644 --- a/brats/README.md +++ b/brats/README.md @@ -12,6 +12,20 @@ git fetch origin pull/39/head:feature/brats && git checkout feature/brats cd ./brats/metrics/mlcube ``` +## Execute docker-based MLCubes with Singularity runner + +```bash +virtualenv -p python3 env && source ./env/bin/activate + +git clone https://github.com/mlcommons/mlcube && cd ./mlcube + +git fetch origin pull/223/head:feature/singularity_with_docker_images && git checkout feature/singularity_with_docker_images + +pip install semver spython && pip install ./mlcube + +pip install --no-deps --force-reinstall ./runners/mlcube_singularity +``` + ## MedPerf API Server To run locally, clone this repo: diff --git a/brats/model/README.md b/brats/model/README.md index 42d0f21..1b08d3f 100644 --- a/brats/model/README.md +++ b/brats/model/README.md @@ -24,13 +24,11 @@ These are the most important files on this project: ```bash ├── mlcube -│ ├── mlcube_cpu.yaml # MLCube CPU configuration, defines the project, author, platform, docker and tasks. -│ ├── mlcube_gpu.yaml # MLCube GPU configuration, here the difference is the target dockerfile. +│ ├── mlcube.yaml # MLCube configuration, defines the project, author, platform, docker and tasks. │ └── workspace │ └── parameters.yaml # File containing all extra parameters. └── project - ├── Dockerfile_CPU # Docker file with instructions to create the image for the CPU version. - ├── Dockerfile_GPU # Docker file with instructions to create the image for the GPU version. + ├── Dockerfile # Docker file with instructions to create the image. ├── mlcube.py # Python entrypoint used by MLCube, contains the logic for MLCube tasks. ├── requirements.txt # Python requirements needed to run the project inside Docker. └── src @@ -53,7 +51,7 @@ In this file (`requirements.txt`) you can add all the python dependencies needed ### Dockerfile -You can use both, CPU or GPU version for the dockerfile (`Dockerfile_CPU`, `Dockerfile_GPU`), also, you can add or modify any steps inside the file, this comes handy when you need to install some OS dependencies or even when you want to change the base docker image, inside the file you can find some information about the existing steps. +In this file users can define the image for CPU or GPU version, also, users add or modify any steps inside the file, this comes handy when you need to install some OS dependencies or even when you want to change the base docker image, inside the file you can find some information about the existing steps. ### Parameters file @@ -61,7 +59,7 @@ This is a yaml file (`parameters.yaml`)that contains all extra parameters that a ### MLCube yaml file -In these files (`mlcube_cpu`, `mlcube_gpu`) you can find the instructions about the docker image and platform that will be used, information about the project (name, description, authors), and also the tasks defined for the project. +In this file you can find the instructions about the docker image and platform that will be used, information about the project (name, description, authors), and also the tasks defined for the project. In the existing implementation you will find 2 tasks: @@ -97,17 +95,11 @@ In the `utilities.py` file you can add some functions that will be useful for yo ## Tasks execution ```bash -# Run example task with CPU support. -mlcube run --mlcube=mlcube_cpu.yaml --task=example +# Run example task. +mlcube run --mlcube=mlcube.yaml --task=example -# Run main task with CPU support. -mlcube run --mlcube=mlcube_cpu.yaml --task=infer - -# Run example task with GPU support. -mlcube run --mlcube=mlcube_gpu.yaml --task=example - -# Run main task with GPU support. -mlcube run --mlcube=mlcube_gpu.yaml --task=infer +# Run main task. +mlcube run --mlcube=mlcube.yaml --task=infer ``` We are targeting pull-type installation, so MLCube images should be available on Docker Hub. If not, try this: diff --git a/brats/model/mlcube/mlcube.yaml b/brats/model/mlcube/mlcube.yaml index af9c07d..1569075 100644 --- a/brats/model/mlcube/mlcube.yaml +++ b/brats/model/mlcube/mlcube.yaml @@ -8,7 +8,7 @@ platform: docker: # Image name. - image: mlcommons/brats_cpu:0.0.1 + image: mlcommons/brats_model:0.0.1 # Docker build context relative to $MLCUBE_ROOT. Default is `build`. build_context: "../project" # Docker file name within docker build context, default is `Dockerfile`. From 4b840fedb7b1e332901bfeed4fdcf94940617d3c Mon Sep 17 00:00:00 2001 From: David Jurado Date: Thu, 28 Apr 2022 18:07:42 -0500 Subject: [PATCH 27/28] Fix Docker image convertion to Singularity --- brats/metrics/project/Dockerfile | 6 +++--- brats/metrics/project/mlcube.py | 2 +- brats/model/mlcube/mlcube.yaml | 2 +- brats/model/project/Dockerfile | 6 +++--- brats/preprocessing/project/Dockerfile | 8 ++++---- brats/preprocessing/project/mlcube.py | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/brats/metrics/project/Dockerfile b/brats/metrics/project/Dockerfile index 436cf7c..83eecbb 100644 --- a/brats/metrics/project/Dockerfile +++ b/brats/metrics/project/Dockerfile @@ -12,11 +12,11 @@ LABEL status="beta" RUN apt-get -y update && apt -y full-upgrade && apt-get -y install apt-utils wget git tar build-essential curl nano # install all python requirements -WORKDIR /app +WORKDIR /workspace COPY ./requirements.txt ./requirements.txt RUN pip3 install -r requirements.txt # copy all files -COPY ./ ./ +COPY ./ /workspace -ENTRYPOINT [ "python3", "mlcube.py"] +ENTRYPOINT [ "python3", "/workspace/mlcube.py"] diff --git a/brats/metrics/project/mlcube.py b/brats/metrics/project/mlcube.py index be570b7..d49dee6 100644 --- a/brats/metrics/project/mlcube.py +++ b/brats/metrics/project/mlcube.py @@ -15,7 +15,7 @@ class EvaluateTask: def run( ground_truth: str, predictions: str, parameters_file: str, output_file: str ) -> None: - cmd = f"python3 metrics.py --ground_truth={ground_truth} --predictions={predictions} --parameters_file={parameters_file} --output_file={output_file}" + cmd = f"python3 /workspace/metrics.py --ground_truth={ground_truth} --predictions={predictions} --parameters_file={parameters_file} --output_file={output_file}" splitted_cmd = cmd.split() process = subprocess.Popen(splitted_cmd, cwd=".") diff --git a/brats/model/mlcube/mlcube.yaml b/brats/model/mlcube/mlcube.yaml index af9c07d..1569075 100644 --- a/brats/model/mlcube/mlcube.yaml +++ b/brats/model/mlcube/mlcube.yaml @@ -8,7 +8,7 @@ platform: docker: # Image name. - image: mlcommons/brats_cpu:0.0.1 + image: mlcommons/brats_model:0.0.1 # Docker build context relative to $MLCUBE_ROOT. Default is `build`. build_context: "../project" # Docker file name within docker build context, default is `Dockerfile`. diff --git a/brats/model/project/Dockerfile b/brats/model/project/Dockerfile index 436cf7c..83eecbb 100644 --- a/brats/model/project/Dockerfile +++ b/brats/model/project/Dockerfile @@ -12,11 +12,11 @@ LABEL status="beta" RUN apt-get -y update && apt -y full-upgrade && apt-get -y install apt-utils wget git tar build-essential curl nano # install all python requirements -WORKDIR /app +WORKDIR /workspace COPY ./requirements.txt ./requirements.txt RUN pip3 install -r requirements.txt # copy all files -COPY ./ ./ +COPY ./ /workspace -ENTRYPOINT [ "python3", "mlcube.py"] +ENTRYPOINT [ "python3", "/workspace/mlcube.py"] diff --git a/brats/preprocessing/project/Dockerfile b/brats/preprocessing/project/Dockerfile index df20286..25aa40f 100644 --- a/brats/preprocessing/project/Dockerfile +++ b/brats/preprocessing/project/Dockerfile @@ -12,13 +12,13 @@ LABEL status="beta" RUN apt-get -y update && apt -y full-upgrade && apt-get -y install apt-utils wget git tar build-essential curl nano # install all python requirements -WORKDIR /app +WORKDIR /workspace COPY ./requirements.txt ./requirements.txt RUN pip3 install -r requirements.txt # copy all files -COPY ./ ./ +COPY ./ /workspace -RUN chmod +x ./run.sh +RUN chmod +x /workspace/run.sh -ENTRYPOINT [ "python3", "mlcube.py"] +ENTRYPOINT [ "python3", "/workspace/mlcube.py"] diff --git a/brats/preprocessing/project/mlcube.py b/brats/preprocessing/project/mlcube.py index d8f9ec6..d5d80dd 100644 --- a/brats/preprocessing/project/mlcube.py +++ b/brats/preprocessing/project/mlcube.py @@ -16,7 +16,7 @@ def run( data_path: str, parameters_file: str, output_path: str ) -> None: - cmd = f"python3 preprocess.py --data_path={data_path} \ + cmd = f"python3 /workspace/preprocess.py --data_path={data_path} \ --parameters_file {parameters_file} --output_path {output_path}" splitted_cmd = cmd.split() From 45a44d93388ceb079028d48cb0fc2e98da014fb7 Mon Sep 17 00:00:00 2001 From: David Jurado Date: Fri, 29 Apr 2022 01:33:33 -0500 Subject: [PATCH 28/28] Add Docker to singularity instructions --- brats/metrics/README.md | 8 +++++++- brats/model/README.md | 6 ++++++ brats/preprocessing/README.md | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/brats/metrics/README.md b/brats/metrics/README.md index 8cb7a29..8524032 100644 --- a/brats/metrics/README.md +++ b/brats/metrics/README.md @@ -88,7 +88,13 @@ The `metrics.py` file contains the main logic of the project, you can modify thi ```bash # Run evaluate task. -mlcube run --mlcube=mlcube_cpu.yaml --task=evaluate +mlcube run --mlcube=mlcube.yaml --task=evaluate +``` + +To use Singularity runner add the flag `--platform=singularity`, example: + +```bash +mlcube run --mlcube=mlcube.yaml --task=evaluate --platform=singularity ``` We are targeting pull-type installation, so MLCube images should be available on Docker Hub. If not, try this: diff --git a/brats/model/README.md b/brats/model/README.md index 1b08d3f..54c57c2 100644 --- a/brats/model/README.md +++ b/brats/model/README.md @@ -102,6 +102,12 @@ mlcube run --mlcube=mlcube.yaml --task=example mlcube run --mlcube=mlcube.yaml --task=infer ``` +To use Singularity runner add the flag `--platform=singularity`, example: + +```bash +mlcube run --mlcube=mlcube.yaml --task=example --platform=singularity +``` + We are targeting pull-type installation, so MLCube images should be available on Docker Hub. If not, try this: ```Bash diff --git a/brats/preprocessing/README.md b/brats/preprocessing/README.md index 01b930d..cbc80dd 100644 --- a/brats/preprocessing/README.md +++ b/brats/preprocessing/README.md @@ -91,7 +91,13 @@ The `run.sh` file is called from `mlcube.py` and it receives the arguments, here ```bash # Run preprocess task. -mlcube run --mlcube=mlcube_cpu.yaml --task=preprocess +mlcube run --mlcube=mlcube.yaml --task=preprocess +``` + +To use Singularity runner add the flag `--platform=singularity`, example: + +```bash +mlcube run --mlcube=mlcube.yaml --task=preprocess --platform=singularity ``` We are targeting pull-type installation, so MLCube images should be available on Docker Hub. If not, try this: