ccm commited on
Commit
173f72d
1 Parent(s): b5690e4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -10
main.py CHANGED
@@ -1,6 +1,7 @@
1
  import numpy
2
  import keras
3
  import gradio
 
4
 
5
  # Building the neural network
6
  model1 = keras.models.Sequential()
@@ -34,14 +35,16 @@ def scale(im, nR, nC):
34
  return numpy.array([[ im[int(nR0 * r / nR)][int(nC0 * c / nC)]
35
  for c in range(nC)] for r in range(nR)])
36
 
 
37
  def predict(mask):
38
- print(mask)
 
 
39
  X = scale(mask, 101, 636)
40
  X = numpy.round(X/255.0)[numpy.newaxis, :, :, numpy.newaxis]
41
- v = model1.predict(X)*255
42
- output = (v - v.min()) / (v.max() - v.min())
43
- print(output.shape)
44
- return output[0, :, :, 0], output[0, :, :, 1], output[0, :, :, 2]
45
 
46
  with gradio.Blocks() as demo:
47
 
@@ -59,11 +62,10 @@ with gradio.Blocks() as demo:
59
  mask = gradio.Image(image_mode="L", source="canvas", label="microstructure")
60
 
61
  btn = gradio.Button("Run!", variant="primary")
62
- exx = gradio.Image(image_mode="L", label="ε-xx")
63
- eyy = gradio.Image(image_mode="L", label="ε-yy")
64
- exy = gradio.Image(image_mode="L", label="ε-xy")
65
 
66
  btn.click(fn=predict, inputs=[mask], outputs=[exx, eyy, exy])
67
 
68
- demo.launch()
69
-
 
1
  import numpy
2
  import keras
3
  import gradio
4
+ import matplotlib.pyplot
5
 
6
  # Building the neural network
7
  model1 = keras.models.Sequential()
 
35
  return numpy.array([[ im[int(nR0 * r / nR)][int(nC0 * c / nC)]
36
  for c in range(nC)] for r in range(nR)])
37
 
38
+
39
  def predict(mask):
40
+ # Get the color map by name:
41
+ cm = matplotlib.pyplot.get_cmap('RdBu')
42
+
43
  X = scale(mask, 101, 636)
44
  X = numpy.round(X/255.0)[numpy.newaxis, :, :, numpy.newaxis]
45
+ v = model1.predict(X)
46
+ output = ((v / max(v.max(), -v.min()))+1.0)/2.0
47
+ return cm(output[0, :, :, 0]), cm(output[0, :, :, 1]), cm(output[0, :, :, 2])
 
48
 
49
  with gradio.Blocks() as demo:
50
 
 
62
  mask = gradio.Image(image_mode="L", source="canvas", label="microstructure")
63
 
64
  btn = gradio.Button("Run!", variant="primary")
65
+ exx = gradio.Image(label="ε-xx")
66
+ eyy = gradio.Image(label="ε-yy")
67
+ exy = gradio.Image(label="ε-xy")
68
 
69
  btn.click(fn=predict, inputs=[mask], outputs=[exx, eyy, exy])
70
 
71
+ demo.launch()