> 该项目是《Problem-independent machine learning (PIML)-based topology optimization—A universal approach》的python复现


## 环境依赖
> PyTorch 2.1.0 CUDA 12.1 Ubuntu 20.04 (没有用到新特性,所以应该对旧版本兼容)

```
# matplotlib==3.8.0
# numpy==1.26.2
# scikit_learn==1.3.0
# torch==2.1.0
pip install -r requirements.txt
```

## Usage
TODO: [done] 用argparse模块管理网络参数
### Train
```
python train.py
# --mod [mod1 mod2 mod3] 参数选择训练数据,默认mod1
# e.g. python train.py --mod mod1
```

### Test
```
python test.py
# --mod [mod1 mod2 mod3] 参数选择测试数据,默认mod3
# --pretrained_model_path <xxx_opt.pt> 选择预训练模型,默认./checkpoints/ANN_mod1/ANN_mod1_opt.pt
# e.g. python test.py --mod mod3 --pretrained_model_path ./checkpoints/ANN_mod1/ANN_mod1_opt.pt
```

### TopOpt with EMsFEA net

```
python topopt_EMsFEA.py
# 参数详见options/topopt_options.py
```

## 数据集
> 通过经典二维拓扑优化代码生成的三组形变、密度数据
>
> Download from:
> 
> http://118.195.195.192:3000/GyeongYun/EMsFEA-net/raw/branch/resources/datasets.zip

mod1: ![](doc/mod1.jpg)

mod2: ![](doc/mod2.jpg)

mod3: ![](doc/mod3.jpg)


## 项目结构
```
.
|-- README.md
|-- checkpoints
|   `-- ...
|-- datasets
|   |-- train
|   |   `--resolution
|   |      |--u
|   |      `--xPhys
|   |-- test
|-- models
|   |-- ANN.py
|   |-- AutoEncoder.py
|   |-- CNN.py
|   `-- __init__.py
|-- options
|   |-- __init__.py
|   |-- base_options.py
|   |-- test_options.py
|   `-- train_options.py
|-- requirements.txt
|-- results
|-- test.py
|-- topopt_EMsFEA.py
|-- train.py
|-- utils
|   |-- data_loader.py
|   |-- data_standardizer.py
|   |-- topopt_88.py
|   `-- utils.py
`-- visualization.ipynb
```