PrakhAI commited on
Commit
b5be8ad
1 Parent(s): 6b89a7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -12,6 +12,9 @@ import tensorflow as tf
12
 
13
  hf_key = text_input = st.text_input("Access token")
14
 
 
 
 
15
  class CNN(nn.Module):
16
  @nn.compact
17
  def __call__(self, x):
@@ -42,13 +45,14 @@ if len(uploaded_files) == 0:
42
  st.write("Please upload an image!")
43
  else:
44
  input = jnp.array([tf.cast(tf.image.resize(tf.convert_to_tensor(Image.open(uploaded_file)), [50, 50]), tf.float32) / 255. for uploaded_file in uploaded_files])
45
- st.write("Input shape: " + str(input.shape))
46
- pred = cnn.apply({"params": params}, input)
47
- st.write("Model Prediction: " + str(pred))
48
- st.write("Model Prediction type: " + str(type(pred)))
49
- st.write("Model Prediction type dir: " + str(dir(pred)))
50
  for (index, image) in enumerate(uploaded_files):
51
  st.image(Image.open(image))
 
 
 
 
 
52
 
53
  def gridify(kernel, grid, kernel_size, scaling=5, padding=1):
54
  scaled_and_padded = np.pad(np.repeat(np.repeat(kernel, repeats=scaling, axis=0), repeats=scaling, axis=1), ((padding,),(padding,),(0,),(0,)), 'constant', constant_values=(-1,))
@@ -60,4 +64,4 @@ with st.expander("See first convolutional layer"):
60
 
61
  with st.expander("See second convolutional layer"):
62
  print(params["Conv_1"]["kernel"].shape)
63
- gridify(params["Conv_1"]["kernel"], grid=(64,96), kernel_size=(3,3))
 
12
 
13
  hf_key = text_input = st.text_input("Access token")
14
 
15
+ def sigmoid(x):
16
+ return 1/(1+e**-x)
17
+
18
  class CNN(nn.Module):
19
  @nn.compact
20
  def __call__(self, x):
 
45
  st.write("Please upload an image!")
46
  else:
47
  input = jnp.array([tf.cast(tf.image.resize(tf.convert_to_tensor(Image.open(uploaded_file)), [50, 50]), tf.float32) / 255. for uploaded_file in uploaded_files])
48
+ prediction = cnn.apply({"params": params}, input)
 
 
 
 
49
  for (index, image) in enumerate(uploaded_files):
50
  st.image(Image.open(image))
51
+ [cat_prob, dog_prob] = jax.nn.softmax(prediction[index])
52
+ if cat_prob > dog_prob:
53
+ st.write(f"Model Prediction - Cat ({100*cat_prob}%), Dog ({100*dog_prob}%)")
54
+ else:
55
+ st.write(f"Model Prediction - Dog ({100*dog_prob}%), Cat ({100*cat_prob}%)")
56
 
57
  def gridify(kernel, grid, kernel_size, scaling=5, padding=1):
58
  scaled_and_padded = np.pad(np.repeat(np.repeat(kernel, repeats=scaling, axis=0), repeats=scaling, axis=1), ((padding,),(padding,),(0,),(0,)), 'constant', constant_values=(-1,))
 
64
 
65
  with st.expander("See second convolutional layer"):
66
  print(params["Conv_1"]["kernel"].shape)
67
+ gridify(params["Conv_1"]["kernel"], grid=(32,64), kernel_size=(3,3))