# SFGAN: Semantic Fusion GAN for semi-supervised learning
Code for paper [**Semantic-Fusion GANs for Semi-Supervised Satellite Image Classification**](https://ieeexplore.ieee.org/abstract/document/8451836/) accepted in the International Conference on Image Processing (**ICIP**) to be held in *Athens, Greece* in October, 2018.
Code is **available now**.
## Requirements
1. Tensorflow 1.5
2. Python 3.5
## Instructions
1. First download the [EuroSAT](http://madm.dfki.de/files/sentinel/EuroSAT.zip) data set and extract the images.
2. Run the file_reader.m to convert the images into a .mat file. This will be used as input for training the network.
3. Run sfgan_train_eval.py to train the network.
N.B. Python 3 is recommended for running this code as the batching gives errornoues results with lower versions of Python. Haven't tried with other versions of Tensorflow.
## Citation
If you use this code for your research, please cite our [paper](https://ieeexplore.ieee.org/abstract/document/8451836/)
```
@inproceedings{roy2018semantic,
title={Semantic-Fusion Gans for Semi-Supervised Satellite Image Classification},
author={Roy, Subhankar and Sangineto, Enver and Sebe, Nicu and Demir, Beg{\"u}m},
booktitle={2018 25th IEEE International Conference on Image Processing (ICIP)},
pages={684--688},
year={2018},
organization={IEEE}
}
```
A commented version of the code will be updated soon.
代码执行过程中遇到问题 :
原因:1.0版本以后models模块已经删除掉了,都整合到examples下面
解决方法:
1、安装低版本的TensorFlow
2、到我的网盘下载models库 链接:https://pan.baidu.com/s/1595QnRri21TOlEHdMtyeMQ 密码:hcup
解压,将models文件夹放到site-packages下的tensorflow文件夹中,不知道site-packages的朋友直接在Python解释器里面import 一个已安装的包,把包名称打印即可看到路径:
个人电脑:source activate tensorflow
python
import tensorflow as tf
tf.__path__输出的路径 '/home/gden/.local/lib/python3.6/site-packages/tensorflow',
实验室电脑在:
我的 在 /home/gis/anaconda3/lib/python3.6/site-packages/tensorflow/里面。放入 下载的models解压。
>>> import numpy
>>> numpy
<module 'numpy' from '/usr/local/lib/python2.7/site-packages/numpy/__init__.pyc'>
>>>
---------------------
2、因为需要
下载文件,解压放入 inception_v3_2016_08_28.tar.gz 放入 model_checkpoint中
trainset = loadmat(data_dir + 'train_64x64.mat') # read the images as .mat format
testset = loadmat(data_dir + 'test_64x64.mat')
两个mat文件,所以先运行matlab执行file_reader.m生成两个文件,放入data文件夹,
把数据EuroSAT解压到data文件夹中。
3、然后下面的代码中models前加tensorflow. 第2句注释换成第三句,即可通过
from tensorflow.models.research.slim.datasets import dataset_utils
#from tensorflow.models.research.slim.nets import inception yinggshi banben wenti huancheng xiamian d e yuju #guo
from tensorflow.contrib.slim.python.slim.nets import inception
#from tensorflow.nets import inception_resnet_v2
import tensorflow as tf
import os
slim = tf.contrib.slim
from tensorflow.models.research.slim.preprocessing import inception_preprocessing
slim nets中包含几种常用的net网络
from tensorflow.contrib.slim.python.slim.nets import alexnet
from tensorflow.contrib.slim.python.slim.nets import inception
from tensorflow.contrib.slim.python.slim.nets import overfeat
from tensorflow.contrib.slim.python.slim.nets import resnet_utils
from tensorflow.contrib.slim.python.slim.nets import resnet_v1
from tensorflow.contrib.slim.python.slim.nets import resnet_v2
from tensorflow.contrib.slim.python.slim.nets import vgg
from tensorflow.python.util.all_util import make_all
import tensorflow as tf
vgg = tf.contrib.slim.nets.vgg
# Load the images and labels.
images, labels = ...
# Create the model.
predictions, _ = vgg.vgg_16(images)
# Define the loss functions and get the total loss.
loss = slim.losses.softmax_cross_entropy(predictions, labels)
---------------------
运行结果:
/home/gis/anaconda3/bin/python /home/gis/PycharmProjects/guo/SFGAN-master/sfgan_train_eval.py
/home/gis/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
trainset shape: (64, 64, 3, 21600)
testset shape: (64, 64, 3, 5400)
WARNING:tensorflow:From /home/gis/PycharmProjects/guo/SFGAN-master/sfgan_train_eval.py:215: softmax_cross_entropy_with_logits (from tensorflow.python.ops.nn_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Future major versions of TensorFlow will allow gradients to flow
into the labels input on backprop by default.
See tf.nn.softmax_cross_entropy_with_logits_v2.
2018-11-24 14:28:28.092339: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-11-24 14:28:28.171398: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-11-24 14:28:28.171650: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.683
pciBusID: 0000:01:00.0
totalMemory: 10.92GiB freeMemory: 10.76GiB
2018-11-24 14:28:28.171661: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
2018-11-24 14:28:28.321343: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10414 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
Epoch 0
Classifier train accuracy: 0.508
Classifier test accuracy 0.3962962962962963
Step time: 8.612806797027588
Epoch time: 2307.5803849697113
Epoch 1
Classifier train accuracy: 0.738
Classifier test accuracy 0.7166666666666667
Step time: 8.125792741775513
Epoch time: 2335.0536658763885
Epoch 2
Classifier train accuracy: 0.794
Classifier test accuracy 0.7666666666666667
Step time: 8.328018426895142
Epoch time: 2366.0408046245575
Epoch 3
Classifier train accuracy: 0.828
Classifier test accuracy 0.7685185185185185
Step time: 8.527539491653442
Epoch time: 2402.784227848053
Epoch 4
Classifier train accuracy: 0.859
Classifier test accuracy 0.8166666666666667
Step time: 8.624815464019775
Epoch time: 2431.8803803920746
Epoch 5
Classifier train accuracy: 0.895
Classifier test accuracy 0.8240740740740741
Step time: 8.8027024269104
Epoch time: 2461.293095588684
Epoch 6
Classifier train accuracy: 0.9
Classifier test accuracy 0.8240740740740741
Step time: 8.957260370254517
Epoch time: 2490.6261053085327
Epoch 7
Classifier train accuracy: 0.907
Classifier test accuracy 0.8425925925925926
Step time: 9.184311628341675
Epoch time: 2523.2131741046906
Epoch 8
Classifier train accuracy: 0.941
Classifier test accuracy 0.8425925925925926
Step time: 9.317538738250732
Epoch time: 2562.020185947418
Epoch 9
Classifier train accuracy: 0.947
Classifier test accuracy 0.8314814814814815
Step time: 9.437634229660034
Epoch time: 2584.778172969818
Epoch 10
Classifier train accuracy: 0.959
Classifier test accuracy 0.8574074074074074
Step time: 9.51582384109497
Epoch time: 2614.294749736786
Epoch 11
Classifier train accuracy: 0.964
Classifier test accuracy 0.8481481481481481
Step time: 9.632224798202515
Epoch time: 2620.98281955719
Epoch 12
Classifier train accuracy: 0.976
Classifier test accuracy 0.8629629629629629
Step time: 9.798041820526123
Epoch time: 2651.6856546401978
Epoch 13
Classifier train accuracy: 0.974
Classifier test accuracy 0.8685185185185185
Step time: 9.952399253845215
Epoch time: 2674.9474260807037
Epoch 14
Classifier train accuracy: 0.979
Classifier test accuracy 0.8518518518518519
Step time: 10.161629915237427
Epoch time: 2702.9086606502533
Epoch 15
Classifier train accuracy: 0.975
Classifier test accuracy 0.8759259259259259
Step time: 10.260272741317749
Epoch time: 2724.9530215263367
Epoch 16
Classifier train accuracy: 0.984
Classifier test accuracy 0.8574074074074074
Step time: 10.436271905899048
Epoch time: 2752.3730642795563
Epoch 17
Classifier train accuracy: 0.984
Classifier test accuracy 0.8518518518518519
Step time: 10.52426028251648
Epoch time: 2775.6411406993866
Epoch 18
Classifier train accuracy: 0.991
Classifier test accuracy 0.8648148148148148
Step time: 10.626144886016846
Epoch time: 2797.360468864441
Epoch 19
Classifier train accuracy: 0.994
Classifier test accuracy 0.8666666666666667
Step time: 10.773233413696289
Epoch time: 2826.7894053459167
Epoch 20
Classifier train accuracy: 0.99
Classifier test accuracy 0.8629629629629629
Step time: 10.957350254058838
Epoch time: 2849.0413353443146
Epoch 21
Classifier train accuracy: 0.992
Classifier test accuracy 0.8611111111111112
Step time: 11.039655923843384
Epoch time: 2873.061153650284
Epoch 22
Classifier train accuracy: 0.986
Classifier test accuracy 0.8611111111111112
Step time: 11.208385944366455
Epoch time: 2896.3946607112885
Epoch 23
Classifier train accuracy: 0.994
Classifier test accuracy 0.8777777777777778
Step time: 11.34923243522644
Epoch time: 2920.891423225403
Epoch 24
Classifier train accuracy: 0.993
Classifier test accuracy 0.8574074074074074
Step time: 11.512229442596436
Epoch time: 2945.0110743045807
Epoch 25
Classifier train accuracy: 0.99