nick-leland commited on
Commit
d8805a9
·
1 Parent(s): 1e312dc

Added a more finalized model prediction

Browse files
app.py CHANGED
@@ -211,13 +211,20 @@ def transform_image(image, func_choice, randomization_check, radius, center_x, c
211
  # Have to convert to image first
212
  result = Image.fromarray(transformed)
213
 
214
- result_bias = str(learn_bias.predict(result))
215
- result_fresh = str(learn_fresh.predict(result))
 
 
 
 
 
 
216
  print("Results")
217
- print(result_bias)
218
- print(result_fresh)
219
 
220
- return transformed, result_bias, result_fresh, vector_field
 
221
 
222
  demo = gr.Interface(
223
  fn=transform_image,
@@ -233,15 +240,22 @@ demo = gr.Interface(
233
  # gr.Slider(0, 0.5, value=0.1, label="Center Smoothness")
234
  # gr.Checkbox(label="Reverse Gradient Direction"),
235
  ],
 
 
 
 
 
 
236
  outputs=[
237
  gr.Image(label="Transformed Image"),
238
  # gr.Image(label="Result", num_top_classes=2)
239
- gr.Textbox(label='Result Bias'),
240
- gr.Textbox(label='Result Fresh'),
241
  gr.Image(label="Gradient Vector Field")
242
  ],
243
  title="Image Transformation Demo!",
244
- description="This is the baseline function that will be used to generate the database for a machine learning model I am working on called 'DistortionMl'! The goal of this model is to detect and then reverse image transformations that can be generated here! You can read more about the project at this repository link : https://github.com/nick-leland/DistortionML. The main function that I was working on is the 'Bulge' function, I can't really guarantee that the others work well (;"
 
245
  )
246
 
247
  demo.launch(share=True)
 
211
  # Have to convert to image first
212
  result = Image.fromarray(transformed)
213
 
214
+ categories = ['Distorted', 'Maze']
215
+
216
+ def clean_output(result_values):
217
+ pred, idx, probs = result_values[0], result_values[1], result_values[2]
218
+ return dict(zip(categories, map(float, probs)))
219
+
220
+ result_bias = learn_bias.predict(result)
221
+ result_fresh = learn_fresh.predict(result)
222
  print("Results")
223
+ result_bias_final = clean_output(result_bias)
224
+ result_fresh_final = clean_output(result_fresh)
225
 
226
+ # return transformed, result_bias, result_fresh, vector_field
227
+ return transformed, result_bias_final, result_fresh_final, vector_field
228
 
229
  demo = gr.Interface(
230
  fn=transform_image,
 
240
  # gr.Slider(0, 0.5, value=0.1, label="Center Smoothness")
241
  # gr.Checkbox(label="Reverse Gradient Direction"),
242
  ],
243
+ examples=[
244
+ [np.asarray(Image.open("examples/1500_maze.jpg")), "Bulge", True, 0.25, 0.5, 0.5, 0.5],
245
+ [np.asarray(Image.open("examples/2048_maze.jpg")), "Bulge", True, 0.25, 0.5, 0.5, 0.5],
246
+ [np.asarray(Image.open("examples/2300_fresh.jpg")), "Bulge", True, 0.25, 0.5, 0.5, 0.5],
247
+ [np.asarray(Image.open("examples/50_fresh.jpg")), "Bulge", True, 0.25, 0.5, 0.5, 0.5]
248
+ ],
249
  outputs=[
250
  gr.Image(label="Transformed Image"),
251
  # gr.Image(label="Result", num_top_classes=2)
252
+ gr.Label(),
253
+ gr.Label(),
254
  gr.Image(label="Gradient Vector Field")
255
  ],
256
  title="Image Transformation Demo!",
257
+ article="If you like this demo, please star the github repository for the project! Located [here!](https://github.com/nick-leland/DistortionML)",
258
+ description="This is the baseline function that will be used to generate the database for a machine learning model I am working on called 'DistortionMl'! The goal of this model is to detect and then reverse image transformations that can be generated here!\nYou can read more about the project at [this repository link](https://github.com/nick-leland/DistortionML). The main function that I was working on is the 'Bulge'/'Volcano' function, I can't really guarantee that the others work as well!\nI have just added the first baseline ML model to detect if a distortion has taken place! It was only trained on mazes though ([Dataset Here](https://www.kaggle.com/datasets/nickleland/distorted-mazes)) so in order for it to detect a distortion you have to use one of the images provided in the examples! Feel free to mess around wtih other images in the meantime though!"
259
  )
260
 
261
  demo.launch(share=True)
examples/1500_maze.jpg ADDED
examples/2048_maze.jpg ADDED
examples/2300_fresh.jpg ADDED
examples/50_fresh.jpg ADDED