Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 30 additions & 0 deletions Dockerfile.server
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM busybox:1.37

LABEL name=fir-server
LABEL version=0.0.1

RUN adduser -D static
USER static
WORKDIR /home/static/fir

COPY --chown=static:static ./foxhole /home/static/fir/foxhole
COPY --chown=static:static ./index.html /home/static/fir
COPY --chown=static:static ./includes /home/static/fir/includes
COPY --chown=static:static ./favicon.ico /home/static/fir
COPY --chown=static:static LICENSE /home/static/fir

ARG PORT=8000
ENV PORT=${PORT}

EXPOSE ${PORT}

# Busybox's httpd doesn't support a mime type for .mjs
# files by default, so we'll need to add it to httpd.conf
# manually. The http daemon also treats .js files as
# application/javascript by default. However, in
# RFC 9239 application/javascript has been marked as
# obselete in favor of text/javascript. So we're overriding
# that mime type as well.
RUN printf ".mjs:text/javascript\n.js:text/javascript\n" > ../httpd.conf

CMD busybox httpd -f -v -p "$PORT" -h /home/static/fir -c /home/static/httpd.conf
25 changes: 25 additions & 0 deletions Dockerfile.trainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# GPU-Enabled TensorFlow Image
FROM tensorflow/tensorflow:2.16.2-gpu

# Path to extracted Foxhole files
ARG WAR_LOCATION
ENV WAR_LOCATION=${WAR_LOCATION}

# Update apt to ensure all packages are available
RUN apt-get update --allow-insecure-repositories

# Setup node and npm with nvm to run all javascript files
SHELL ["/bin/bash", "--login", "-c", "-i"]
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
RUN nvm install 20.10
RUN nvm use 20.10

# Install pipenv for python
RUN pip3 install pipenv

# Install dependencies for image manipulation
RUN apt-get install -y --allow-unauthenticated imagemagick
RUN apt-get install -y --allow-unauthenticated optipng

# Run the build script
CMD sh build.sh ${WAR_LOCATION}
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,60 @@ Currently a bit of a hack around fir as a proof of concept but thanks to their s

Feel free to open an issue if you notice anything not working or have a suggestion on how it can be improved.

## Deployment
### Local
To deploy a non-containerized server run:
```
cd fir
python3 -m http.server
```
### Docker
#### Building the Docker Container
To build the docker container run:
```
docker build -f Dockerfile.server --tag 'fir_server' .
```

##### Overriding the listen port
If you'd like to override the override the port the server listens on run:
```
docker build -f Dockerfile.server --build-arg PORT=<override port> --tag 'fir_server' .
```
#### Running the Docker Container
To run the FIR server in the built docker continer:
```
docker run -p <host port>:<fir port> fir_server
```
The `-p` argument maps the host port to the fir server port inside the container. FIR defaults to listening on port
8000. To override the port please see [this section](#overriding-the-listen-port).

## Development
Standalone website:
```
cd fir
python3 -m http.server
```

To build the google spreadsheet sidebar, run `./sundial/gs-build.sh` and find the files to be added to Google Apps Script in `./sundial/gs-build`.

## Training

### Standalone

The standalone method will require you to manually install all the necessary dependencies, such as Node, NPM, TensorFlow, etc.
To begin training, simply run `build.sh <FModel-Data-Directory>`.

### Docker

Training can also be performed using a Docker container instead. [https://docs.docker.com/desktop/features/wsl/]
If you plan to use your GPU(s) for training, you will need to install NVIDIA drivers and the NVIDIA Container Toolkit. [https://docs.nvidia.com/ai-enterprise/deployment/vmware/latest/docker.html]

Build the docker container by running docker `docker build -f Dockerfile.trainer --tag 'fir_trainer' .`

If you only want to utilize your CPU for training, run `docker run -f Dockerfile.trainer -it --rm -v $PWD:/tmp -w /tmp -e WAR_LOCATION=<FModel-Data-Directory> fir_trainer`

If you want to utilize both your CPU and GPU(s) for training, run `docker run -f Dockerfile.trainer --gpus all -it --rm -v $PWD:/tmp -w /tmp -e WAR_LOCATION=<FModel-Data-Directory> fir_trainer`

## License
All original source code and contributions available under MIT License.

Expand Down
16 changes: 8 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ then
fi

warLocation=$(cd "${1}"; pwd)
version='naval-57'
version='infantry-61'

parseCatalog() {
echo "Parsing catalog. (downloading / updating npm packages)"
Expand All @@ -30,11 +30,6 @@ generateIconTraining() {
rangeMax=$(expr ${cpus} - 1)
seq 0 $rangeMax | xargs -I@ -n1 -P$cpus node generate_training.js "${warLocation}" ../foxhole/${version}/catalog.json training @ $cpus

# Textured Icons mod uses the same icon for both FieldMGAmmo and MGAmmo. This
# confuses the model, and the icon looks more like MGAmmo, so ignore the
# FieldMGAmmo icon.
rm training/FieldMGAmmo*/textured-icons-*.png || true

./find-duplicates.sh $cpus

echo "Copying each training png to jpg."
Expand Down Expand Up @@ -76,9 +71,10 @@ buildClassifier() {

CUDNN_PATH=$(dirname $(pipenv run python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)"))
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDNN_PATH/lib
export TF_FORCE_GPU_ALLOW_GROWTH=true

rm -r model-tf || true
pipenv run python train.py 50 rgb 0.10 0.005 ../catalog/training/
pipenv run python train.py 100 rgb 0.20 0.005 ../catalog/training/

echo "Training complete, assembling results."
rm -r ../foxhole/${version}/classifier || true
Expand All @@ -87,7 +83,11 @@ buildClassifier() {

#pipenv run python train.py 16 grayscale 0.05 0.05 quantity_training

pipenv run tensorflowjs_converter --input_format tf_saved_model --output_format=tfjs_graph_model model-tf ../foxhole/${version}/classifier
cd convert
pipenv clean
pipenv install
pipenv run tensorflowjs_converter --input_format tf_saved_model --output_format=tfjs_graph_model ../model-tf ../../foxhole/${version}/classifier
cd ..

pipenv run python sort_json.py ../foxhole/${version}/classifier/model.json

Expand Down
Loading