Beispiel #1
0
def _handler_l1(ir_path, vis_path, model_path, model_pre_path, ssim_weight, index, output_path=None):
	ir_img = get_train_images(ir_path, flag=False)
	vis_img = get_train_images(vis_path, flag=False)
	dimension = ir_img.shape

	ir_img = ir_img.reshape([1, dimension[0], dimension[1], dimension[2]])
	vis_img = vis_img.reshape([1, dimension[0], dimension[1], dimension[2]])

	ir_img = np.transpose(ir_img, (0, 2, 1, 3))
	vis_img = np.transpose(vis_img, (0, 2, 1, 3))

	print('img shape final:', ir_img.shape)

	with tf.Graph().as_default(), tf.Session() as sess:

		# build the dataflow graph
		infrared_field = tf.placeholder(
			tf.float32, shape=ir_img.shape, name='content')
		visible_field = tf.placeholder(
			tf.float32, shape=ir_img.shape, name='style')

		dfn = DenseFuseNet(model_pre_path)

		enc_ir,enc_ir_res_block,enc_ir_res_block1,enc_ir_res_block2 = dfn.transform_encoder(infrared_field)
		enc_vis,enc_vis_res_block,enc_vis_res_block1,enc_vis_res_block2 = dfn.transform_encoder(visible_field)

		target = tf.placeholder(
		    tf.float32, shape=enc_ir.shape, name='target')
		block1 = tf.placeholder(
			tf.float32, shape=enc_ir_res_block1.shape, name='block1')
		block2= tf.placeholder(
			tf.float32, shape=enc_ir_res_block2.shape, name='block2')
		output_image = dfn.transform_decoder(target,block1,block2)

		# restore the trained model and run the style transferring
		saver = tf.train.Saver()
		saver.restore(sess, model_path)

		enc_ir_temp, enc_vis_temp,ir_block1,ir_block2,vis_block1,vis_block2 = sess.run([enc_ir, enc_vis,enc_ir_res_block1,enc_ir_res_block2 ,enc_vis_res_block1,enc_vis_res_block2], feed_dict={infrared_field: ir_img, visible_field: vis_img})
		feature = L1_norm(enc_ir_temp, enc_vis_temp)
		t_block1=L1_norm(ir_block1,vis_block1)

		t_block2 = L1_norm(ir_block2, vis_block2)
		output = sess.run(output_image, feed_dict={target: feature ,block1:t_block1,block2:t_block2})
		save_images(ir_path, output, output_path,
		            prefix='fused' + str(index), suffix='_densefuse_l1norm_'+str(ssim_weight))
def _handler_l1(content_name, style_name, model_path, model_pre_path, ssim_weight, index, output_path=None):
    infrared_path = content_name
    visible_path = style_name

    content_img = get_train_images(infrared_path, flag=False)
    style_img   = get_train_images(visible_path, flag=False)
    dimension = content_img.shape

    content_img = content_img.reshape([1, dimension[0], dimension[1], dimension[2]])
    style_img   = style_img.reshape([1, dimension[0], dimension[1], dimension[2]])

    content_img = np.transpose(content_img, (0, 2, 1, 3))
    style_img = np.transpose(style_img, (0, 2, 1, 3))
    print('content_img shape final:', content_img.shape)

    with tf.Graph().as_default(), tf.Session() as sess:

        # build the dataflow graph
        content = tf.placeholder(
            tf.float32, shape=content_img.shape, name='content')
        style = tf.placeholder(
            tf.float32, shape=style_img.shape, name='style')

        dfn = DenseFuseNet(model_pre_path)

        enc_c = dfn.transform_encoder(content)
        enc_s = dfn.transform_encoder(style)

        target = tf.placeholder(
            tf.float32, shape=enc_c.shape, name='target')

        output_image = dfn.transform_decoder(target)

        # restore the trained model and run the style transferring
        saver = tf.train.Saver()
        saver.restore(sess, model_path)

        enc_c_temp, enc_s_temp = sess.run([enc_c, enc_s], feed_dict={content: content_img, style: style_img})
        feature = L1_norm(enc_c_temp, enc_s_temp)

        output = sess.run(output_image, feed_dict={target: feature})
        save_images(infrared_path, output, output_path,
                    prefix='fused' + str(index), suffix='_densefuse_l1norm_'+str(ssim_weight))

    return output
def _handler_rgb_l1(ir_path, vis_path, model_path, model_pre_path, ssim_weight, index, output_path=None):
	# ir_img = get_train_images(ir_path, flag=False)
	# vis_img = get_train_images(vis_path, flag=False)
	ir_img = get_train_images_rgb(ir_path, flag=False)
	vis_img = get_train_images_rgb(vis_path, flag=False)
	dimension = ir_img.shape

	ir_img = ir_img.reshape([1, dimension[0], dimension[1], dimension[2]])
	vis_img = vis_img.reshape([1, dimension[0], dimension[1], dimension[2]])

	ir_img = np.transpose(ir_img, (0, 2, 1, 3))
	vis_img = np.transpose(vis_img, (0, 2, 1, 3))

	ir_img1 = ir_img[:, :, :, 0]
	ir_img1 = ir_img1.reshape([1, dimension[0], dimension[1], 1])
	ir_img2 = ir_img[:, :, :, 1]
	ir_img2 = ir_img2.reshape([1, dimension[0], dimension[1], 1])
	ir_img3 = ir_img[:, :, :, 2]
	ir_img3 = ir_img3.reshape([1, dimension[0], dimension[1], 1])

	vis_img1 = vis_img[:, :, :, 0]
	vis_img1 = vis_img1.reshape([1, dimension[0], dimension[1], 1])
	vis_img2 = vis_img[:, :, :, 1]
	vis_img2 = vis_img2.reshape([1, dimension[0], dimension[1], 1])
	vis_img3 = vis_img[:, :, :, 2]
	vis_img3 = vis_img3.reshape([1, dimension[0], dimension[1], 1])

	print('img shape final:', ir_img1.shape)

	with tf.Graph().as_default(), tf.Session() as sess:
		infrared_field = tf.placeholder(
			tf.float32, shape=ir_img1.shape, name='content')
		visible_field = tf.placeholder(
			tf.float32, shape=ir_img1.shape, name='style')

		dfn = DenseFuseNet(model_pre_path)

		enc_ir = dfn.transform_encoder(infrared_field)
		enc_vis = dfn.transform_encoder(visible_field)

		target = tf.placeholder(
			tf.float32, shape=enc_ir.shape, name='target')

		output_image = dfn.transform_decoder(target)

		# restore the trained model and run the style transferring
		saver = tf.train.Saver()
		saver.restore(sess, model_path)

		enc_ir_temp, enc_vis_temp = sess.run([enc_ir, enc_vis], feed_dict={infrared_field: ir_img1, visible_field: vis_img1})
		feature = L1_norm(enc_ir_temp, enc_vis_temp)
		output1 = sess.run(output_image, feed_dict={target: feature})

		enc_ir_temp, enc_vis_temp = sess.run([enc_ir, enc_vis], feed_dict={infrared_field: ir_img2, visible_field: vis_img2})
		feature = L1_norm(enc_ir_temp, enc_vis_temp)
		output2 = sess.run(output_image, feed_dict={target: feature})

		enc_ir_temp, enc_vis_temp = sess.run([enc_ir, enc_vis], feed_dict={infrared_field: ir_img3, visible_field: vis_img3})
		feature = L1_norm(enc_ir_temp, enc_vis_temp)
		output3 = sess.run(output_image, feed_dict={target: feature})

		output1 = output1.reshape([1, dimension[0], dimension[1]])
		output2 = output2.reshape([1, dimension[0], dimension[1]])
		output3 = output3.reshape([1, dimension[0], dimension[1]])

		output = np.stack((output1, output2, output3), axis=-1)
		output = np.transpose(output, (0, 2, 1, 3))
		save_images(ir_path, output, output_path,
		            prefix='fused' + str(index), suffix='_densefuse_l1norm_'+str(ssim_weight))
Beispiel #4
0
def _handler_mix(ir_path,
                 vis_path,
                 model_path,
                 model_pre_path,
                 ssim_weight,
                 index,
                 output_path=None):
    mix_block = []
    ir_img = get_train_images(ir_path, flag=False)
    vis_img = get_train_images(vis_path, flag=False)
    dimension = ir_img.shape
    ir_img = ir_img.reshape([1, dimension[0], dimension[1], dimension[2]])
    vis_img = vis_img.reshape([1, dimension[0], dimension[1], dimension[2]])
    ir_img = np.transpose(ir_img, (0, 2, 1, 3))
    vis_img = np.transpose(vis_img, (0, 2, 1, 3))

    print('img shape final:', ir_img.shape)
    with tf.Graph().as_default(), tf.Session() as sess:
        infrared_field = tf.placeholder(tf.float32,
                                        shape=ir_img.shape,
                                        name='content')
        visible_field = tf.placeholder(tf.float32,
                                       shape=vis_img.shape,
                                       name='style')

        # -----------------------------------------------

        dfn = DenseFuseNet(model_pre_path)

        #sess.run(tf.global_variables_initializer())

        enc_ir, enc_ir_res_block, enc_ir_block, enc_ir_block2 = dfn.transform_encoder(
            infrared_field)
        enc_vis, enc_vis_res_block, enc_vis_block, enc_vis_block2 = dfn.transform_encoder(
            visible_field)

        result = tf.placeholder(tf.float32, shape=enc_ir.shape, name='target')

        saver = tf.train.Saver()
        saver.restore(sess, model_path)

        enc_ir_temp, enc_ir_res_block_temp, enc_ir_block_temp, enc_ir_block2_temp = sess.run(
            [enc_ir, enc_ir_res_block, enc_ir_block, enc_ir_block2],
            feed_dict={infrared_field: ir_img})
        enc_vis_temp, enc_vis_res_block_temp, enc_vis_block_temp, enc_vis_block2_temp = sess.run(
            [enc_vis, enc_vis_res_block, enc_vis_block, enc_vis_block2],
            feed_dict={visible_field: vis_img})

        block = L1_norm(enc_ir_block_temp, enc_vis_block_temp)
        block2 = L1_norm(enc_ir_block2_temp, enc_vis_block2_temp)

        first_first = L1_norm(enc_ir_res_block_temp[0],
                              enc_vis_res_block_temp[0])
        first_second = Strategy(enc_ir_res_block_temp[1],
                                enc_vis_res_block_temp[1])
        #first_third = L1_norm_attention(enc_ir_res_block_temp[2],feation_ir, enc_vis_res_block_temp[2],feation_vis)
        #first_four = L1_norm_attention(enc_ir_res_block_temp[3],feation_ir, enc_vis_res_block_temp[3],feation_vis)
        first_third = L1_norm(enc_ir_res_block_temp[2],
                              enc_vis_res_block_temp[2])
        first_four = Strategy(enc_ir_res_block_temp[3],
                              enc_vis_res_block_temp[3])
        first_first = tf.concat(
            [first_first, tf.to_int32(first_second, name='ToInt')], 3)
        first_first = tf.concat(
            [first_first, tf.to_int32(first_third, name='ToInt')], 3)
        first_first = tf.concat([first_first, first_four], 3)

        first = first_first

        second = L1_norm(enc_ir_res_block_temp[6], enc_vis_res_block_temp[6])
        third = L1_norm(enc_ir_res_block_temp[9], enc_vis_res_block_temp[9])

        feature = 1 * first + 0.1 * second + 0.1 * third

        #---------------------------------------------------------
        # block=Strategy(enc_ir_block_temp,enc_vis_block_temp)
        # block2=L1_norm(enc_ir_block2_temp,enc_vis_block2_temp)
        #---------------------------------------------------------

        feature = feature.eval()

        output_image = dfn.transform_decoder(result, block, block2)

        # output = dfn.transform_decoder(feature)
        # print(type(feature))
        # output = sess.run(output_image, feed_dict={result: feature,enc_res_block:block,enc_res_block2:block2})
        output = sess.run(output_image, feed_dict={result: feature})

        save_images(ir_path,
                    output,
                    output_path,
                    prefix='fused' + str(index),
                    suffix='_mix_' + str(ssim_weight))
Beispiel #5
0
def _handler_mix_a(ir_path, vis_path, model_path, model_pre_path,model_path_a,model_pre_path_a, ssim_weight, index, output_path=None):
	ir_img = get_train_images(ir_path, flag=False)
	vis_img = get_train_images(vis_path, flag=False)
	dimension = ir_img.shape
	ir_img = ir_img.reshape([1, dimension[0], dimension[1], dimension[2]])
	vis_img = vis_img.reshape([1, dimension[0], dimension[1], dimension[2]])
	ir_img = np.transpose(ir_img, (0, 2, 1, 3))
	vis_img = np.transpose(vis_img, (0, 2, 1, 3))


	g2 = tf.Graph()  # 加载到Session 2的graph

	sess2 = tf.Session(graph=g2)  # Session2

	with sess2.as_default():  # 1
		with g2.as_default(),tf.Session() as sess:
			infrared_field = tf.placeholder(
				tf.float32, shape=ir_img.shape, name='content')
			visible_field = tf.placeholder(
				tf.float32, shape=vis_img.shape, name='style')

			dfn = DenseFuseNet(model_pre_path)

			# sess.run(tf.global_variables_initializer())

			enc_ir, enc_ir_res_block, enc_ir_block, enc_ir_block2 = dfn.transform_encoder(infrared_field)
			enc_vis, enc_vis_res_block, enc_vis_block, enc_vis_block2 = dfn.transform_encoder(visible_field)

			result = tf.placeholder(
				tf.float32, shape=enc_ir.shape, name='target')

			saver = tf.train.Saver()
			saver.restore(sess, model_path)
			print("______000________")
			feature_a,feature_b=_get_attention(ir_path,vis_path,model_path_a,model_pre_path_a)
			print("______111________")
			print(feature_a[0].shape)

			enc_ir_temp, enc_ir_res_block_temp, enc_ir_block_temp, enc_ir_block2_temp = sess.run(
				[enc_ir, enc_ir_res_block, enc_ir_block, enc_ir_block2], feed_dict={infrared_field: ir_img})
			print("______222________")
			enc_vis_temp, enc_vis_res_block_temp, enc_vis_block_temp, enc_vis_block2_temp = sess.run(
				[enc_vis, enc_vis_res_block, enc_vis_block, enc_vis_block2], feed_dict={visible_field: vis_img})
			print("______333________")
			# ----------------------------------------------------------------------------------------------------------
			# ----------------------------------------------------------------------------------------------------------


			#----------------------------------跳跃部分-----------------------------------------------------------------
			block = Strategy(enc_ir_block_temp, enc_vis_block_temp) * 0
			block2 = Strategy(enc_ir_block2_temp, enc_vis_block2_temp) * 0
			#block = L1_norm_attention(enc_ir_block_temp, feature_a, enc_vis_block_temp, feature_b)
			#block2 = L1_norm_attention(enc_ir_block2_temp, feature_a, enc_vis_block2_temp, feature_b)
			# ----------------------------------------------------------------------------------------------------------

			first_first = Strategy(enc_ir_res_block_temp[0], enc_vis_res_block_temp[0])
			#first_first = L1_norm_attention(enc_ir_res_block_temp[0],feature_a, enc_vis_res_block_temp[0],feature_b)
			first_second = Strategy(enc_ir_res_block_temp[1], enc_vis_res_block_temp[1])
			#first_second = L1_norm_attention(enc_ir_res_block_temp[1],feature_a, enc_vis_res_block_temp[1],feature_b)
			first_third = Strategy(enc_ir_res_block_temp[2], enc_vis_res_block_temp[2])
			#first_third = L1_norm_attention(enc_ir_res_block_temp[2], feature_a, enc_vis_res_block_temp[2], feature_b)
			#first_third = L1_norm(enc_ir_res_block_temp[2], enc_vis_res_block_temp[2]) * 0
			first_four = Strategy(enc_ir_res_block_temp[3], enc_vis_res_block_temp[3])
			#first_four = L1_norm_attention(enc_ir_res_block_temp[3], feature_a, enc_vis_res_block_temp[3], feature_b)
			#first_four = L1_norm(enc_ir_res_block_temp[3],  enc_vis_res_block_temp[3])
			first_first = tf.concat([first_first, tf.to_int32(first_second, name='ToInt')], 3)
			first_first = tf.concat([first_first, tf.to_int32(first_third, name='ToInt')], 3)
			first_first = tf.concat([first_first, first_four], 3)
			print("______444________")

			first = first_first

			# -------------------------------------空洞卷积部分---------------------------------------------------------
			#second = L1_norm_attention(enc_ir_res_block_temp[6],feature_a, enc_vis_res_block_temp[6],feature_b)
			print (enc_ir_res_block_temp[6].shape)
			second = L1_norm(enc_ir_res_block_temp[6], enc_vis_res_block_temp[6])
			print("______4545________")
			third = Strategy(enc_ir_res_block_temp[9], enc_vis_res_block_temp[9])
			print("______555________")
			# ----------------------------------------------------------------------------------------------------------


			# ----------------------------------------------------------------------------------------------------------
			# ----------------------------------------------------------------------------------------------------------



			# -------------------------------------空洞卷积部分---------------------------------------------------------
			feature = 1 * first + 0.1 * second + 0.1 * third
			# ----------------------------------------------------------------------------------------------------------
			print ("51515151")

			# ---------------------------------------------------------
			# block=Strategy(enc_ir_block_temp,enc_vis_block_temp)
			# block2=L1_norm(enc_ir_block2_temp,enc_vis_block2_temp)
			# ---------------------------------------------------------

			feature = feature.eval()


			print ("52525252")

			# --------------将特征图压成单通道----------------------------------
			#feature_map_vis_out = sess.run(tf.reduce_sum(feature_a[0], 3, keep_dims=True))
			#feature_map_ir_out = sess.run(tf.reduce_sum(feature_b[0],3, keep_dims=True))
			# ------------------------------------------------------------------
			print (result.shape)
			print ("5555555")
			output_image = dfn.transform_decoder(result, block, block2)
			print("______666________")
			# output = dfn.transform_decoder(feature)
			# print(type(feature))
			# output = sess.run(output_image, feed_dict={result: feature,enc_res_block:block,enc_res_block2:block2})

			output = sess.run(output_image, feed_dict={result: feature})
			print (output_image.shape)
			print("______777________")
			save_images(ir_path, output, output_path,
			            prefix='' + str(index), suffix='-1')
def _handler_rgb_l1(images_path,
                    model_path,
                    model_pre_path,
                    index,
                    output_path=None):
    size = len(images_path)
    images = ["" for x in range(size)]
    ir_img1 = ["" for x in range(size)]
    ir_img2 = ["" for x in range(size)]
    ir_img3 = ["" for x in range(size)]
    for x in range(0, size):
        images[x] = get_train_images_rgb(images_path[x], flag=False)
        dimension = images[x].shape

        images[x] = images[x].reshape(
            [1, dimension[0], dimension[1], dimension[2]])

        images[x] = np.transpose(images[x], (0, 2, 1, 3))

        ir_img1[x] = images[x][:, :, :, 0]
        ir_img1[x] = ir_img1[x].reshape([1, dimension[0], dimension[1], 1])
        ir_img2[x] = images[x][:, :, :, 1]
        ir_img2[x] = ir_img2[x].reshape([1, dimension[0], dimension[1], 1])
        ir_img3[x] = images[x][:, :, :, 2]
        ir_img3[x] = ir_img3[x].reshape([1, dimension[0], dimension[1], 1])

    print('img shape final:', ir_img1[0].shape)

    with tf.Graph().as_default(), tf.Session() as sess:
        images_field = ["" for x in range(size)]
        for x in range(0, size):
            images_field[x] = tf.placeholder(tf.float32,
                                             shape=ir_img1[0].shape)

        dfn = DenseFuseNet(model_pre_path)
        enc_irs = ["" for x in range(size)]
        enc_irs = dfn.transform_encoder(images_field)

        target = tf.placeholder(tf.float32,
                                shape=enc_irs[0].shape,
                                name='target')

        output_image = dfn.transform_decoder(target)

        # restore the trained model and run the style transferring
        saver = tf.train.Saver()
        saver.restore(sess, model_path)

        enc_ir_temps = sess.run(
            enc_irs, feed_dict={i: d
                                for i, d in zip(images_field, ir_img1)})
        feature = L1_norm(enc_ir_temps)
        output1 = sess.run(output_image, feed_dict={target: feature})

        enc_ir_temps = sess.run(
            enc_irs, feed_dict={i: d
                                for i, d in zip(images_field, ir_img2)})
        feature = L1_norm(enc_ir_temps)
        output2 = sess.run(output_image, feed_dict={target: feature})

        enc_ir_temps = sess.run(
            enc_irs, feed_dict={i: d
                                for i, d in zip(images_field, ir_img3)})
        feature = L1_norm(enc_ir_temps)
        output3 = sess.run(output_image, feed_dict={target: feature})

        output1 = output1.reshape([1, dimension[0], dimension[1]])
        output2 = output2.reshape([1, dimension[0], dimension[1]])
        output3 = output3.reshape([1, dimension[0], dimension[1]])

        output = np.stack((output1, output2, output3), axis=-1)
        output = np.transpose(output, (0, 2, 1, 3))
        save_images(images_path,
                    output,
                    output_path,
                    prefix='fused' + str(index),
                    suffix='_densefuse_l1norm')
Beispiel #7
0
def _handler_l1(ir_path,
                vis_path,
                model_path,
                model_pre_path,
                ssim_weight,
                index,
                output_path=None):
    ir_img = get_train_images(ir_path, True, flag=False)
    vis_img, Cr, Cb = get_train_images(vis_path, False, flag=False)
    dimension = ir_img.shape

    ir_img = ir_img.reshape([1, dimension[0], dimension[1], dimension[2]])
    vis_img = vis_img.reshape([1, dimension[0], dimension[1], dimension[2]])

    #ir_img = np.transpose(ir_img, (0, 2, 1, 3))
    #vis_img = np.transpose(vis_img, (0, 2, 1, 3))

    print('img shape final:', ir_img.shape)

    with tf.Graph().as_default(), tf.Session() as sess:

        # build the dataflow graph
        infrared_field = tf.placeholder(tf.float32,
                                        shape=ir_img.shape,
                                        name='content')
        visible_field = tf.placeholder(tf.float32,
                                       shape=ir_img.shape,
                                       name='style')

        dfn = DenseFuseNet(model_pre_path)

        enc_ir1, enc_ir2, enc_ir3 = dfn.transform_encoder(infrared_field)
        enc_vis1, enc_vis2, enc_vis3 = dfn.transform_encoder(visible_field)

        temp_enc = tf.concat([enc_ir1, enc_ir2], 3)
        temp_out = tf.concat([temp_enc, enc_ir3], 3)

        target = tf.placeholder(tf.float32,
                                shape=temp_out.shape,
                                name='target')

        output_image = dfn.transform_decoder(target)

        # restore the trained model and run the style transferring
        saver = tf.train.Saver()
        saver.restore(sess, model_path)

        enc_ir1, enc_ir2, enc_ir3, enc_vis1, enc_vis2, enc_vis3 = sess.run(
            [enc_ir1, enc_ir2, enc_ir3, enc_vis1, enc_vis2, enc_vis3],
            feed_dict={
                infrared_field: ir_img,
                visible_field: vis_img
            })
        target_feature1_l1 = L1_norm(enc_ir1, enc_vis1)
        target_feature2_l1 = L1_norm(enc_ir2, enc_vis2)
        target_feature3_l1 = L1_norm(enc_ir3, enc_vis3)

        temp_l1 = tf.concat([target_feature1_l1, target_feature2_l1], 3)
        out_l1 = tf.concat([temp_l1, target_feature3_l1], 3)

        out_l1 = out_l1.eval()

        output = sess.run(output_image, feed_dict={target: out_l1})
        output = output.squeeze()
        result = np.dstack([output, Cr, Cb])
        result = cv2.cvtColor(result, cv2.COLOR_YCrCb2BGR)
        cv2.imwrite((output_path + str(index) +
                     '_multiScale_densefuse_l1_MRSPECT_ssim' +
                     str(ssim_weight) + '.jpg'), result)
def _handler_mix_a(ir_path, vis_path, model_path, model_pre_path,model_path_a,model_pre_path_a, ssim_weight, index, output_path=None):
	ir_img = get_train_images(ir_path, flag=False)
	vis_img = get_train_images(vis_path, flag=False)
	dimension = ir_img.shape
	ir_img = ir_img.reshape([1, dimension[0], dimension[1], dimension[2]])
	vis_img = vis_img.reshape([1, dimension[0], dimension[1], dimension[2]])
	ir_img = np.transpose(ir_img, (0, 2, 1, 3))
	vis_img = np.transpose(vis_img, (0, 2, 1, 3))


	g2 = tf.Graph()  # 加载到Session 2的graph

	sess2 = tf.Session(graph=g2)  # Session2

	with sess2.as_default():  # 1
		tf.global_variables_initializer()
		with g2.as_default(),tf.Session() as sess:
			infrared_field = tf.placeholder(
				tf.float32, shape=ir_img.shape, name='content')
			visible_field = tf.placeholder(
				tf.float32, shape=vis_img.shape, name='style')

			dfn = DenseFuseNet(model_pre_path)

			# atn = attention.Attention(None)

			# sess.run(tf.global_variables_initializer())

			enc_ir, enc_ir_res_block, enc_ir_block, enc_ir_block2 = dfn.transform_encoder(infrared_field)
			enc_vis, enc_vis_res_block, enc_vis_block, enc_vis_block2 = dfn.transform_encoder(visible_field)

			result = tf.placeholder(
				tf.float32, shape=enc_ir.shape, name='target')

			saver = tf.train.Saver()
			saver.restore(sess, model_path)

			# ------------------------attention------------------------------------------------------
			# feature_a,feature_b=_get_attention(ir_path,vis_path,model_path_a,model_pre_path_a)
			# print("______+++________")
			# print(feature_a[0].shape)
			# ------------------------attention------------------------------------------------------

			enc_ir_temp, enc_ir_res_block_temp, enc_ir_block_temp, enc_ir_block2_temp = sess.run(
				[enc_ir, enc_ir_res_block, enc_ir_block, enc_ir_block2], feed_dict={infrared_field: ir_img})
			enc_vis_temp, enc_vis_res_block_temp, enc_vis_block_temp, enc_vis_block2_temp = sess.run(
				[enc_vis, enc_vis_res_block, enc_vis_block, enc_vis_block2], feed_dict={visible_field: vis_img})

			# enc_ir_block2_temp = atn.get_attention(enc_ir_block2_temp)
			# enc_vis_block2_temp = atn.get_attention(enc_vis_block2_temp)

			#saver.restore(sess, model_path_a)
			#atn = attention.Attention(None)
			#enc_ir_block2_temp = tf.convert_to_tensor(enc_ir_block2_temp)
			#enc_vis_block2_temp = tf.convert_to_tensor(enc_vis_block2_temp)
			#enc_ir_block2_temp = atn.get_attention(enc_ir_block2_temp)
			#enc_vis_block2_temp = atn.get_attention(enc_vis_block2_temp)

			#enc_vis_block2_temp = sess.run(enc_vis_block2_temp)
			#enc_ir_block2_temp = sess.run(enc_ir_block2_temp)

			enc_ir_block2_temp, enc_vis_block2_temp,ir_att,vis_att = _get_attention(enc_ir_block2_temp, enc_vis_block2_temp, model_path_a)

			# ------------------------------------------------------------------------------------------------------------
			#------------------------------------------------------------------------------------------------------------
			block = 1 * enc_vis_block_temp# + 0.3 * enc_ir_block_temp
			block2 = 1 * enc_ir_block2_temp #+ 0.2 * enc_vis_block2_temp

			#first_first = Strategy(enc_ir_res_block_temp[0], enc_vis_res_block_temp[0])
			#first_first = L1_norm(enc_ir_res_block_temp[0], enc_vis_res_block_temp[0])
			#first_second = Strategy(enc_ir_res_block_temp[1], enc_vis_res_block_temp[1])
			#first_second = L1_norm(enc_ir_res_block_temp[1], enc_vis_res_block_temp[1])
			#first_third = Strategy(enc_ir_res_block_temp[2], enc_vis_res_block_temp[2])
			#first_third = L1_norm_attention(enc_ir_res_block_temp[2],feature_a, enc_vis_res_block_temp[2],feature_b)
			#first_four = Strategy(enc_ir_res_block_temp[3], enc_vis_res_block_temp[3])
			#first_four = L1_norm_attention(enc_ir_res_block_temp[3],feature_a, enc_vis_res_block_temp[3],feature_b)
			#first_first = tf.concat([first_first, tf.to_int32(first_second, name='ToInt')], 3)
			#first_first = tf.concat([first_first, tf.to_int32(first_third, name='ToInt')], 3)
			#first_first = tf.concat([first_first, first_four], 3)

			#first = first_first

			first = Strategy(enc_ir_res_block_temp[3], enc_vis_res_block_temp[3])
			second = L1_norm(enc_ir_res_block_temp[6], enc_vis_res_block_temp[6])
			third = L1_norm(enc_ir_res_block_temp[9], enc_vis_res_block_temp[9])
			# ------------------------------------------------------------------------------------------------------------
			# ------------------------------------------------------------------------------------------------------------


			feature = 1 * first + 1 * second + 1 * third

			# ---------------------------------------------------------
			# block=Strategy(enc_ir_block_temp,enc_vis_block_temp)
			# block2=L1_norm(enc_ir_block2_temp,enc_vis_block2_temp)
			# ---------------------------------------------------------

			#feature = feature.eval()

			# --------------将特征图压成单通道----------------------------------
			feature_map_vis_out = sess.run(tf.reduce_sum(ir_att, 3, keep_dims=True))
			feature_map_ir_out = sess.run(tf.reduce_sum(vis_att,3, keep_dims=True))
			# ------------------------------------------------------------------
			#saver.restore(sess, model_path)
			output_image = dfn.transform_decoder(feature, block, block2)

			# output = dfn.transform_decoder(feature)
			# print(type(feature))
			# output = sess.run(output_image, feed_dict={result: feature,enc_res_block:block,enc_res_block2:block2})
			#output = sess.run(output_image, feed_dict={result: feature})

			output = sess.run(output_image)

			save_images(ir_path, output, output_path,
						prefix='fused' + str(index), suffix='_mix_' + str(ssim_weight))
			save_images(ir_path, feature_map_vis_out, output_path,
			            prefix='fused' + str(index), suffix='vis' + str(ssim_weight))
			save_images(ir_path, feature_map_ir_out, output_path,
			            prefix='fused' + str(index), suffix='ir' + str(ssim_weight))