David Fischinger commited on
Commit
f5d6164
1 Parent(s): 884246e

added test images

Browse files
app.py CHANGED
@@ -10,6 +10,8 @@ from IMVIP_Supplementary_Material.scripts import dfutils #methods used for DF-Ne
10
  DESCRIPTION = """# DF-Net
11
  The Digital Forensics Network is designed and trained to detect and locate image manipulations.
12
  More information can be found in this [publication](https://zenodo.org/record/8214996)
 
 
13
  """
14
 
15
  IMG_SIZE=256
@@ -17,7 +19,8 @@ IMG_SIZE=256
17
  tf.experimental.numpy.experimental_enable_numpy_behavior()
18
  #np.warnings.filterwarnings('error', category=np.VisibleDeprecationWarning)
19
 
20
-
 
21
 
22
  def check_forgery_df(img):
23
  shape_original = img.shape
@@ -45,18 +48,74 @@ def check_forgery_df(img):
45
  return resized_image
46
 
47
 
48
-
49
  def evaluate(img):
50
  pre_t = check_forgery_df(img)
51
  st.image(pre_t, caption="White area indicates potential image manipulations.")
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
 
55
  st.markdown(DESCRIPTION)
56
 
57
- uploaded_file = st.file_uploader("Please upload an image", type=["jpeg", "jpg", "png"])
58
 
59
- if uploaded_file is not None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  #load models
61
  model_path1 = "IMVIP_Supplementary_Material/models/model1/"
62
  model_path2 = "IMVIP_Supplementary_Material/models/model2/"
@@ -85,4 +144,8 @@ if uploaded_file is not None:
85
  evaluate(reversed_image)
86
 
87
 
 
 
 
 
88
 
 
10
  DESCRIPTION = """# DF-Net
11
  The Digital Forensics Network is designed and trained to detect and locate image manipulations.
12
  More information can be found in this [publication](https://zenodo.org/record/8214996)
13
+
14
+ #### Select example image or upload your own image:
15
  """
16
 
17
  IMG_SIZE=256
 
19
  tf.experimental.numpy.experimental_enable_numpy_behavior()
20
  #np.warnings.filterwarnings('error', category=np.VisibleDeprecationWarning)
21
 
22
+ model_M1 = None
23
+ model_M2 = None
24
 
25
  def check_forgery_df(img):
26
  shape_original = img.shape
 
48
  return resized_image
49
 
50
 
 
51
  def evaluate(img):
52
  pre_t = check_forgery_df(img)
53
  st.image(pre_t, caption="White area indicates potential image manipulations.")
54
 
55
+ def start_evaluation(uploaded_file):
56
+ #load models
57
+ model_path1 = "IMVIP_Supplementary_Material/models/model1/"
58
+ model_path2 = "IMVIP_Supplementary_Material/models/model2/"
59
+
60
+ #tfsm_layer1 = tf.keras.layers.TFSMLayer(model_path1, call_endpoint='serving_default')
61
+ #tfsm_layer2 = tf.keras.layers.TFSMLayer(model_path2, call_endpoint='serving_default')
62
+ #
63
+ #input_shape = (256, 256, 3)
64
+ #inputs = Input(shape=input_shape)
65
+
66
+ ##create the model
67
+ #outputs1 = tfsm_layer1(inputs)
68
+ #model_M1 = Model(inputs, outputs1)
69
+
70
+ #outputs2 = tfsm_layer2(inputs)
71
+ #model_M2 = Model(inputs, outputs2)
72
+
73
+ model_M1 = tf.keras.models.load_model("IMVIP_Supplementary_Material/models/model1/") #tf.keras.models.load_model("IMVIP_Supplementary_Material/models/model1/")
74
+ model_M2 = tf.keras.models.load_model("IMVIP_Supplementary_Material/models/model2/")
75
+
76
+ # Convert the file to an opencv image.
77
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
78
+ opencv_image = cv2.imdecode(file_bytes, 1)
79
+ reversed_image = opencv_image[:, :, ::-1]
80
+ st.image(reversed_image, caption="Input Image")
81
+ evaluate(reversed_image)
82
 
83
 
84
  st.markdown(DESCRIPTION)
85
 
 
86
 
87
+ img_path1 = "example_images/Sp_D_NRD_A_nat0095_art0058_0582"
88
+ img_path2 = "example_images/Sp_D_NRN_A_nat0083_arc0080_0445"
89
+ img_path3 = "example_images/Sp_D_NRN_A_ani0088_cha0044_0441"
90
+ image_paths = [img_path1+".jpg", img_path2+".jpg", img_path3+".jpg"]
91
+ gt_paths = [img_path1+"_gt.png", img_path2+"_gt.png", img_path3+"_gt.png"]
92
+ # Display images in a table format
93
+ img = None
94
+ for idx, image_path in enumerate(image_paths):
95
+ cols = st.columns([2, 2, 2, 2]) # Define column widths
96
+
97
+ # Place the button in the first column
98
+ if cols[0].button(f"Select Image {idx+1}", key=idx):
99
+ img = Image.open(image_path)
100
+
101
+ # Place the image in the second column
102
+ with cols[1]:
103
+ st.image(image_path, use_column_width=True, caption="Example Image "+str(idx+1))
104
+
105
+ # Place the ground truth in the third column
106
+ with cols[2]:
107
+ st.image(gt_paths[idx], use_column_width=True, caption="Ground Truth")
108
+
109
+ if img is not None:
110
+ start_evaluation(img)
111
+
112
+ def reset_image_select():
113
+ img = None
114
+
115
+
116
+
117
+
118
+ def start_evaluation(uploaded_file):
119
  #load models
120
  model_path1 = "IMVIP_Supplementary_Material/models/model1/"
121
  model_path2 = "IMVIP_Supplementary_Material/models/model2/"
 
144
  evaluate(reversed_image)
145
 
146
 
147
+ uploaded_file= None
148
+ uploaded_file = st.file_uploader("Please upload an image", type=["jpeg", "jpg", "png"], on_change=reset_image_select)
149
+ if (uploaded_file is not None) and (img is None):
150
+ start_evaluation(uploaded_file)
151
 
example_images/Sp_D_NRD_A_nat0095_art0058_0582.jpg ADDED
example_images/Sp_D_NRD_A_nat0095_art0058_0582_gt.png ADDED
example_images/Sp_D_NRN_A_ani0088_cha0044_0441.jpg ADDED
example_images/Sp_D_NRN_A_ani0088_cha0044_0441_gt.png ADDED
example_images/Sp_D_NRN_A_nat0083_arc0080_0445.jpg ADDED
example_images/Sp_D_NRN_A_nat0083_arc0080_0445_gt.png ADDED